Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended/effective request payload for a REST PUT method?

Tags:

rest

I see two types of examples in various places. One uses form fields like

curl -X PUT -d "phone=123.456.7890" "http://127.0.0.1/services/rest/user/123"

and the other uses an XML content like (some variation of) this

echo "<user><id>123</id><phone>123.456.7890</phone></user>" | curl -X PUT -d @- "http://127.0.0.1/services/rest/user/"

It seems like using the form fields has the advantage of brevity and clearly identifying the client's intent by targeting just the modified fields, but makes it awkward to address "deeper" metadata.

Using the XML content has an advantage of being more complete, but the disadvantage of the overhead of figuring out which field the client is actually modifying (assuming that they send back the entire resource with small modifications).

Is there a best practice, or even a more-common practice?

like image 366
kevmurray Avatar asked Nov 06 '22 22:11

kevmurray


1 Answers

It could be something like JSON(P)? (I'm not sure about exact syntax):

$ echo '{user: {id: 123, phone: 123.456.7890}}' |\
> curl -X PUT -d @- 'http://127.0.0.1/services/rest/user/'

Or

$ echo '{phone: 123.456.7890}' |\
> curl -X PUT -d @- 'http://127.0.0.1/services/rest/user/123.json'
like image 190
jfs Avatar answered Nov 15 '22 08:11

jfs