user5512021
user5512021

Reputation:

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?

Upvotes: 1

Views: 6387

Answers (2)

cassiomolin
cassiomolin

Reputation: 131147

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.

Upvotes: 2

Evert
Evert

Reputation: 99841

No, there are no real restrictions. I recently created a REST api that used a mixture of:

  • text/markdown
  • text/csv
  • text/html
  • application/hal+json

This one of the neat things about REST services. An image is just an image

Upvotes: 2

Related Questions