RESTful way to send commands

后端 未结 3 1914
走了就别回头了
走了就别回头了 2020-12-12 13:40

How do you send \"commands\" to a RESTful server?

Use case: My server caches certain information so that it does not have to read the database every time that inform

3条回答
  •  無奈伤痛
    2020-12-12 14:24

    I'd suggest this:

    • Create a resource that you can GET which will tell you client how to send the command, similar to an HTML form, using a POST if there are side-effects to this command.
    • POST to the resource to trigger the command and return the URI to a new resource you create during the execution of this POST request (e.g. http://server.example/results/00001), perhaps with a 204 (No Content) status and Location header or a redirect (depending on which client can understand).
    • Let the client check the results on this resource using GET. You may also return the representation for this resource (or something similar) as the entity returned by the POST just before.

    It's up to you to decide on the lifecycle of the result resource. It could be short-lived if you don't need to store the results for long. The URI could be constructed from a UUID for example.

提交回复
热议问题