How can Socket.io and RESTFul work together?

前端 未结 2 1681
星月不相逢
星月不相逢 2020-12-04 10:38

(I\'m not familiar to RESTFul, please correct me if my concept is wrong)

In RESTFul architecture, we map every action to an URL. If I click \"post a article\", may i

2条回答
  •  我在风中等你
    2020-12-04 11:06

    You're defining a handler for actions that map to REST over http. POST and GET generally refer to update and query over an entity. There's absolutely no reason you can't just define a handler for generic versions of these CRUD operations that can be used in both contexts. The way I generally do this is by introducing the concept of a 'route' to the real-time transport, and mapping those back to the same CRUD handlers.

    You have a session, you can impose the same ACL, etc.

     +---------------------------------+
     |                                 |
     |      BROWSER                    |
     |                                 |
     +--+--^-------------------+---^---+
        |  |                   |   |
        |  |                   |   |
     +--v--+---+            +--v---+---+
     |         |            |          |
     | HTTP    |            | SOCKET.IO|
     +--+---^--+            +--+---^---+
        |   |                  |   |
     +--v---+------------------v---+---+
     |                                 |
     |        ROUTING/PUBSUB           |
     +-+--^-------+--^-------+--^------+
       |  |       |  |       |  |
     +-v--+--+  +-v--+--+  +-v--+-+
     |       |  |       |  |      |
     | USERS |  | ITEMS |  |ETC   |
     +-------+  +-------+  +------+
         ENTITY CRUD HANDLERS
    

提交回复
热议问题