6

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

muneebShabbir
  • 2,362
  • 4
  • 26
  • 43

1 Answers1

10

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
Andrii Muzalevskyi
  • 2,997
  • 13
  • 18