I am a backend developer and I am writing a restful application. I have a question about how best to design the endpoints.
I have a database table that stores values (I just provided an example)
|id (int)|A (bool)| B (bool)|
| 1 | 0 | 0 |
| 2 | 0 | 1 |
| 3 | 1 | 1 |
Business logic:
- If A=0 B=0 then we consider "no action"
- If A=0 B=1 then we consider that "the action has begun"
- If A=1 B=1 then we consider "action ended"
How can I do it better?
Style 1
Make one endpoint [PUT] /action
to the body of which I will expect from the frontender
{"id": int, "A": bool, "B": bool}
In this case, I'm shifting to the front-end the writing of the logic for separating the use cases of the endpoint
Style 2
Make a separate endpoint for each business function
[POST] /action/begin
[POST] /action/end
[DELETE] /action
In this case I expect only the id
of the object from the front, and I will fill in A and B myself