Search code examples
jsonxmlrestdataformat

REST Data format


This might sound like a very basic question but what are the different data formats that a REST API can handle?

I am aware that JSON, XML are the most common ones. I read here that it can handle plain text and HTML also.

Question is that is there any restrictions as to what REST can handle?


Solution

  • Question is that is there any restrictions as to what REST can handle?

    The central piece of REST is the resource. And a resource can have n representations. Refer to this answer for details.

    There's no restrictions on the media types that REST applications can use to represent the resources. It's up to each implementation. We frequently see REST APIs using JSON as a mean to represent resources: JSON is a pretty popular data format and can be parsed by a number of programming languages.

    From the chapter 5 of the Fielding's dissertation, where the REST architectural style is defined:

    REST components perform actions on a resource by using a representation to capture the current or intended state of that resource and transferring that representation between components. A representation is a sequence of bytes, plus representation metadata to describe those bytes. Other commonly used but less precise names for a representation include: document, file, and HTTP message entity, instance, or variant.

    The goal behind supporting multiple representations for the same resource is that the client would be able to choose the representation that best suit their needs. It's called content negotiation.