12

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,500
  • 4
  • 29
  • 46

1 Answers1

12

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
  • 3,261
  • 16
  • 20