Home > Enterprise >  Should I use GET or POST in the API when I want to query data based on an ID passed by the user to t
Should I use GET or POST in the API when I want to query data based on an ID passed by the user to t

Time:10-16

router.post() or router.get()?

when I want to GET data based on a particular ID passed to the API

CodePudding user response:

GET  --> To get data
POST --> To create/update resource(s)

In your case you need to query some data based on user. What you can do is you can pass your user-id as a URL parameter or query parameter. It should be a GET request.

example:

Pass user-id as a URL parameter

[GET] https://www.example.com/api/v1/post/100 

pass user-id as a query parameter

[GET] https://www.example.com/api/v1/post?user-id=100
  • Related