Event Based interaction style in REST

前端 未结 5 747
夕颜
夕颜 2021-01-31 05:07

I am currently struggling with a design issue involving REST. The application I am designing has a requirement to send out events and also support pub/sub style of interaction.

5条回答
  •  滥情空心
    2021-01-31 05:29

    Just a fast check on the REST constraints:

    • client-server architecture
    • stateless
    • cache
    • uniform interface
      • identification of resource
      • manipulation of resource through representations
      • self-desriptive messages
      • hypermedia of the engine of application state
    • layered system
    • code on demand (optional)

    From the Fielding dissertation:

    The client-server style is the most frequently encountered of the architectural styles for network-based applications. A server component, offering a set of services, listens for requests upon those services. A client component, desiring that a service be performed, sends a request to the server via a connector. The server either rejects or performs the request and sends a response back to the client.

    Btw. an event based system would probably violate most of the constraints. It is hard to define things like hypermedia the engine of application state without clients (since the other name of application state is client state) and hyperlinks (since they are meaningless by pub/sub), and so on...

    Anyways it is an interesting question how to design an event based system somewhat similar to REST. I think you should publish self-descriptive messages containing RDF, but that's just a tip. Polling can be a viable solution, but if I were you I would not try to force REST on an event based system...

    update 2016.05.15.

    As far as I understand the client - server architecture - Fielding describes here and here in his dissertation - uses always REQ/REP communication. The client sends the request and the REST service responds. If you want to have something like PUB/SUB without the violation of the client - server constraint, the only way to do that is the usage of polling. If you don't want to use polling, then ofc. you can use a REST service and a websocket service together, it is not forbidden...

提交回复
热议问题