When you use REST to create a new entry using a POST, I see some APIs such as Google's specify that you send XML as part of the request while others specify that you send key/value pairs. Is there a standard or best practice for REST POST-s?
A POST method is used to send data to a server via API. It also creates subordinate resources, such as a file in a directory. REST Services are a folder that can hold any number of REST methods.
Any REST request includes four essential parts: an HTTP method, an endpoint, headers, and a body.
The REST API supports the following data formats: application/json. application/json indicates JavaScript Object Notation (JSON) and is used for most of the resources. application/xml indicates eXtensible Markup Language (XML) and is used for selected resources.
JSON and XML REST data formats The two most common data exchange formats are JSON and XML, and many RESTful web services can use both formats interchangeably, as long as the client can request the interaction to happen in either format.
Any representation format that works is okay, with the stipulation that you should try very hard to use standard formats such as Atom where they exist.
Update Here's a relevant quote from Roy Fielding (co-author of the HTTP standard, and the person who articulated REST in his PhD dissertation). How you design the representations used in your web service is of central importance:
A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources [...]
Be sure to read the follow-on Q&A.
It depends on the REST service implementer.
If the REST service is an adaptation of an existing html HTML form post key value pairs are generally easier to start off with.
When posting information from JavaScript it is usually easier to use JSON.
XML is used often because it is easy for humans to understand and there are heaps of tools in every language/platform that can deal with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With