0

I'm writing a web app with node/express and I'm trying to set up some restful routes. Basically I have some generic items and I have a page that has a list of these items. so I've set up the following route:

router.get('/items')...

I'm currently setting up add/update items as well, but I'm not sure if I should set up a PUT for add and POST for update, or use POST for both? I've read that POST is acceptable for both add/update, but if I use post for add and update, then I have to use the same route, is this correct? Which would mean I have to pass back some sort of 'action' parameter to tell the route what action to take.

is this a situation where I should use PUT and POST separately?

Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127

1 Answers1

1

You can use post to do both the insert and update with a url pattern like this

POST -> items/  -- add an item
POST -> items/{itemId} -- updates the given item with the id itemId

Refer this for a more detailed description

https://stackoverflow.com/a/630475/381407

Community
  • 1
  • 1
Amila
  • 2,779
  • 1
  • 27
  • 31