REST - What exactly is meant by Uniform Interface?

前端 未结 4 1490
无人共我
无人共我 2021-01-30 02:34

Wikipedia has:

Uniform interface

The uniform interface constraint is fundamental to the design of any REST service.[14] The uniform i

4条回答
  •  后悔当初
    2021-01-30 03:20

    Using interfaces to decouple classes from the implementation of their dependencies is a pretty old concept. I am surprised that you haven't heard of it...

    By REST you use the same concept to decouple the client from the implementation of the REST service. In order to do define such an interface (contract between the client and the service) you have to use standards. This is because if you want an internet size network of REST services, you have to enforce global concepts, like standards to make them understand each other.

    • Identification of resources - You use the URI (IRI) standard to identify a resource. In this case a resource is a web document.

    • Manipulation of resources through these representations - You use the HTTP standard to describe communication. So for example GET means that you want to retrieve data about the URI identified resource. You can describe an operation with a HTTP method and an URI.

    • Self-descriptive messages - You use standard MIME types and (standard) RDF vocabs to make messages self-descriptive. So the client can find the data by checking the semantics, and it don't have to know the application specific data structure the service uses.

    • Hypermedia as the engine of application state (A.K.A. HATEOAS) - You use hyperlinks and possibly URI templates to decouple the client from the application specific URI structure. You can annotate these hyperlinks with semantics e.g. IANA link relations, so the client will understand what they mean.

提交回复
热议问题