Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST post format

Tags:

rest

http-post

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?

like image 500
Marcus Leon Avatar asked Oct 02 '09 01:10

Marcus Leon


People also ask

What is the POST method in REST?

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.

What are the four REST POST?

Any REST request includes four essential parts: an HTTP method, an endpoint, headers, and a body.

What format does REST use?

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.

Does REST have a format?

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.


2 Answers

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.

like image 200
Jim Ferrans Avatar answered Oct 24 '22 19:10

Jim Ferrans


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.

like image 25
leonm Avatar answered Oct 24 '22 21:10

leonm