4

I am designing a RESTful API when I noticed something strange.

When I make a POST request for creating a new record, the form data is sent in request payload.

But when I make a PUT request to update a record, it appends form data in the URL, very similar to GET request.

Now a URL has certain length limit. So what would happen if PUT request has larger data than this limit.

Will the PUT request fail?

Is it unsafe to use PUT instead of POST to update a record having large form data?

EDIT: I am using NodeJS server. I am using restangular(angular framework) to build my PUT request.

aBhijit
  • 4,524
  • 8
  • 32
  • 53
  • When you say *it* appends, what is *it*? Namely, what are you using to build the PUT request? – quickshiftin Jun 28 '14 at 16:37
  • I am using NodeJS server and by 'it' I mean my browser/front-end/client. I am using restangular(angular framework) to build my PUT request. – aBhijit Jun 28 '14 at 16:38
  • If you need to update a specific resource, use PATCH. PUT should be reserved for either creating a new resource or providing an entirely new version of a resource. – thecoshman Jun 30 '14 at 08:27

2 Answers2

2

Use customPUT to send the form data in payload.

baseObj.customPUT(newObj).then(function(xyz){})
roshan
  • 2,104
  • 2
  • 19
  • 32
1

Have a look at these threads

Sounds like you can basically set a Content-type: multipart/form-data header and be golden. Basically comes down to configuration of the request with restangular and support thereof on the NodeJS server.

Community
  • 1
  • 1
quickshiftin
  • 55,146
  • 9
  • 56
  • 76