Home > Software design >  Is a REST API supposed to support multiple protocols
Is a REST API supposed to support multiple protocols

Time:09-09

Fielding has written in his blog entry REST APIs must be hypertext-driven that:

A REST API should not be dependent on any single communication protocol, though its successful mapping to a given protocol may be dependent on the availability of metadata, choice of methods, etc. In general, any protocol element that uses a URI for identification must allow any URI scheme to be used for the sake of that identification. [Failure here implies that identification is not separated from interaction.]

From my reading of this, any REST API must support more than one protocol in order to be considered restful.

Would an application that would fit all other conditions not be considered restful, if the application only supports one protocol such as HTTP?

CodePudding user response:

Fielding designed REST for HTTP 1.1 machine to machine communication. It has many constraints: https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm Afaik. only HTTP fulfills all of them and even if you use HTTP you must use it in a specific way. Though I don't know much about other protocols. What's certain, that you cannot use REST for websockets, because the communication is stateful and it violates the statelessness constraint.

CodePudding user response:

From my reading of this, any REST API must support more than one protocol in order to be considered restful.

I don't believe that's quite the right way to read it.

Recall that the web is the reference implementation of the REST architectural style. Most of the identifiers will be https/http; but we also find ftp, and mailto, and about. Fielding's point is that, for the purposes of identifying resources, our mechanisms should be scheme agnostic.

any protocol element that uses a URI for identification must allow any URI scheme to be used for the sake of that identification. (emphasis added)

We've got an entire registry full of URI schemes, and for the purposes of identifying resources, they all have equal standing.

Link: <mailto://[email protected]>; rel="author"; anchor="https://stackoverflow.com/questions/73654298/is-a-rest-api-supposed-to-support-multiple-protocols"

That's a perfectly fine link relation, indicating that there is an author relationship between two resources.

Fielding doesn't mean that web servers also have to be mail servers; or that browsers need to figure out what you meant when you put a mailto URI in an image tag.


It may be useful to review Fielding's follow up essay, Specialization:

My dissertation is written to a certain audience: experts in the fields of software engineering and network protocol design....

  • Related