REST (Representational State Transfer)

Postman - RFC 5785 Defining Well-Known Uniform Resource Identifiers (URIs)

What does REST abbreviate for?

Representational State Transfer

Who invented REST?

Roy Thomas Fielding -

What are the key concepts covered in REST?

In a RESTful application, think of components of your application as resources, and HTTP verbs as actions for manipulating and accessing those resources.

  1. Resources: Application state and functionality are abstracted into resources. Every resource is uniquely addressable via a global identifier (URI in HTTP). All resources share a uniform interface for transfer of state between client and server. Resource consists of a constrained set of well defined operations. Resource consists of a constrained set of content types, each optionally supporting code on demand. A resource may have multiple representation.
  2. Protocol:
    1. REST consist of a protocol which is client-server, stateless, cacheable, layered. HTTP separates the notions of a web server and a web browser. This allows the implementation of each to vary from the other based on the client-server principle. When used RESTfully, HTTP is stateless. Each message contains all the information necessary to understand the request. As a result, neither the client nor the server needs to remember any state between messages. (Other articles indicate that state can be maintained on the client side, but not on the server side).
    2. In order to manipulate these resources, components of the network communicates via standardized interface (HTTP). Any connector (components, servers, caches, tunnels, firewalls, etc.) can mediate the request. An application can interact with a resource by knowing two things: the identifier of the resource, and the action required. It does not need to know whether there are caches, proxies, gateways, firewalls, tunnels, or anything else between it and the server actually holding the information. The application does, however, need to understand the format of the information returned.
    3. REST's client-server separation of concerns simplifies component implementation, reduces the complexity of connector semantics, improves the effectiveness of performance tuning, and increase scalability of pure server components. Layered system allow intermediaries — proxies, gateways, and firewalls — to be introduced at various points in the communication without changing the interfaces between components, thus allowing them to assist in communication translation or improve performance via large-scale, shared caching. REST enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods, and media types are used to indicate semantics and exchange information, and response explicitly indicate cacheability.

What are the HTTP verbs?

  • GET: Use to implement the Read portion of a CRUD application
  • POST: Use to implement the Update portion of a CRUD application
  • PUT: Used to implement the Create portion of a CRUD application
  • DELETE: Used to implement the Delete portion of a CRUD application

What are the actions of an resource in a RESTful application?

  1. index
  2. new: Display the form for the user to create a new resource
  3. create: Handle the actual creation of the resource
  4. show
  5. edit
  6. update
  7. destroy
GET     /forums              ->  index
GET     /forums/new          ->  new
POST    /forums              ->  create
GET     /forums/:forum       ->  show
GET     /forums/:forum/edit  ->  edit
PUT     /forums/:forum       ->  update
DELETE  /forums/:forum       ->  destroy
GET    /movies    -> find all
GET    /movies/:id    -> findOne
POST    /movies    -> create
PUT    /movies/:id    -> update
DELETE    /movies/:id    -> delete

GET        /pet    List all pets
GET        /pet/findByStatus    Finds Pets by status
GET        /pet/{petId}    Find pet by Id
POST    /pet    Add a new pet to the store
POST    /pet/{petId}    Updates a pet in the store with form data
POST    /pet/{petId}/uploadImage    Upload an image
DELETE    /pet/{petId}    Delete a pet
HTTP Verb Purpose Entire Collection (e.g. /customers) Entire Collection (e.g. /customers)
GET Read / Retrieve 200 (OK), list of customers. Use pagination, sorting and filtering to navigate big lists. 200 (OK), single customer. 404 (Not Found), if ID not found or invalid.
POST Create 201 (Created), 'Location' header with link to /customers/{id} containing new ID. 404 (Not Found), 409 (Conflict) if resource already exists..
PUT Update/Replace 405 (Method Not Allowed), unless you want to update/replace every resource in the entire collection. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
PATCH Update/Modify 405 (Method Not Allowed), unless you want to modify the collection itself. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
DELETE Delete 405 (Method Not Allowed), unless you want to delete the whole collection—not often desirable. 200 (OK). 404 (Not Found), if ID not found or invalid.

What are other client-server technologies that REST is typically compared against?

  1. RPC vs REST
  2. SOAP vs REST
  3. SOA vs REST

What are some remaining questions?

  1. How can we design a RESTful banking application? Look at the smaller stuffs. A banking applications involves the following objects: users, user preferences, accounts. These can be created, added, edited
  2. How can we design a RESTful medical application? Similar to designing a RESTful banking application.
  3. What are the pros and cons of using REST?
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License