REST Fundamental Principles

4

In this Infoq article , the author highlights the five fundamental tenets of REST:

  • Give all things an Identifier
  • Link things (resources / identifier)
  • Use standardized methods
  • Features with multiple representations
  • Communicate without status
  • But one of them would like to help me understand better, this is the principle Use standardized methods . In summary the author says that:

      

    In a RESTful HTTP approach, you would have to start with an inteface   the HTTP protocol of the application. Could you   do something like this:

    My question:

    • How would this interface (based on the image) be? Home
    • What would be the implementation of recurso (ID - Identificador) if you want to pass a json object for example
    asked by anonymous 23.09.2015 / 03:17

    1 answer

    3
      

    How would this interface look (based on the image)?

    Depends on your system, but typically a system that implements the REST API (Web API 2 is one of the frameworks that implements the standard) is supported by these four methods (% , GET , POST and PUT ). Here is a list of all methods supported by the HTTP protocol . Most of them are not essential. You implement if you want.

    The interface is usually defined by the default route + method. In your example, you know that if you call DELETE by /orders , you get the complete list of entities of type GET of service, and if you pass a serialized object by order (as a JSON, which is the most common, even an XML), you are inserting a new entity of type PUT into that service store.

    In the case of Web API 2, documentation on the interfaces is automatically generated by the framework . This feature is known as order .

      

    How would the feature (ID) look like if you want to pass a json object, for example?

    It depends on each service. If you implement a service accepting that ApiExplorer will be defined by a id request or even PUT (which is not recommended, but it is possible). Most services define the id of the new record by itself. When this happens, the new record data is returned in the request response header. You can read more about this here ("Creating a Resource" section).

        
    23.09.2015 / 05:16