I am creating Rest API but I am confused in URL structure. I have to send just one parameter to server in my Post request. should I send it through path variable or in request body? what are the best practices?
Example Current URL:
api/v1/users/{id}/name/{name}
name
is the variable I want to send to server for to change state
Thanks
Sending parametersYou can send path and query parameters with your requests using the URL field and the Params tab.
HTTP POST request We use POST to create a new resource. A POST request requires a body in which you define the data of the entity to be created. A successful POST request would be a 200 response code. In our weather app, we could use a POST method to add weather data about a new city.
@PathVariable can be used in any type of request method (GET, POST, DELETE, etc).
URL usually identifies resource you want to update.
So the data should go inside in request body
To update user name you may send this to server:
POST api/v1/users/{id} HTTP/1.1
Content-Type: application/x-www-form-urlencoded
name=string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With