Answer the question
In order to leave comments, you need to log in
What is the best way to design a REST API?
Greetings!
When designing the API, I encountered a misunderstanding of the idempotency of methods in the context of business logic. Please help.
Suppose there is a service for turning on, turning off and restarting computers, and each operation here is asynchronous (so that the client does not wait for a response); then it is logical to have these resources and methods for them:
Answer the question
In order to leave comments, you need to log in
Some painfully strange ways.
But in general, yes - everything should be POST-ami here, since it is impossible to cancel the canceled operation.
Well, IMHO, such logic is poorly placed on the rest, so it’s quite ok to do
Create a new task
POST /api/machines/{machineId}/jobs
And indicate in the body that it is start/stop/reset
Cancel
POST /api/machines /{machineId}/jsobs/{jobId}/cancel
Not DELETE, because by semantics the resource should disappear after DELETE.
To get a list
GET /api/machines/{machineId}/jobs
To get information on a specific task
GET /api/machines/{machineId}/jobs/{jobId}
If you need to get a list of tasks to include:
GET /api/machines/{ machineId}/jobs?type=start
By naming, kmk, the word "machine" and "job" looks better, and not "computer" and "operation"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question