D
D
driverx182018-08-19 13:17:43
API
driverx18, 2018-08-19 13:17:43

What is the best way to do routing for a POST request?

I have a user, the user has a list of devices (techniques). Let's say I want a person to click "Add a new device" from a mobile device (iPhone, Android), what is the best way to implement routing and implementation? I have two options:
1) Send a request to the /device/ address in the POST parameters of which will be name and user_id (to whom the device is bound).
2) Send a request to the address: /users/{id}/device/ and send only the name of the device in the POST request.
But I do not know about the second option, whether it is possible to send {id} to the POST, or not.
I would be glad for advice, because I entered the development of api only yesterday)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
napa3um, 2018-08-19
@napa3um

Both schemes are acceptable, the choice depends on how you use your API. I suspect that your application is supposed to navigate through the entire list of devices, regardless of the user associated with it. It turns out that the first option is more suitable, it will allow you to have a separate REST resource for displaying and manipulating devices outside of the user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question