What is REST?

A brief introduction to where REST comes from and what REST actually is.

REST - Representational State Transfer - is a paradigm that enables abstract and structured communication between applications. The core of REST is to create a unified contract so that senders and receivers can exchange content in a consistent manner.
It is based on HTTP.

Although REST originated in 2000, it has only been widely used since around 2012. REST is considered the successor to SOAP and is today’s de facto standard for HTTP-based API communication; however, there are (better) alternatives depending on the use case.

Beginnings

The original design was based on the presumption that all the necessary capabilities for the beginnings of REST were already provided by HTTP, XML or the general HTTP client functionality in browsers and applications.
REST has now evolved much that content is now delivered in the more efficient Json and rarely with XML.

// https://my-rest-api.com/v1/task
<Tasks>
  <Task Id="123" isDone="false">
    <Title>Buy apples</Title>
    <CreatedOn>2018-04-26T16:47+00:00</CreatedOn>
    <!-- ... -->
  </Task>
<Tasks>

Most important principles

REST uses HTTP features and capabilities for content exchange.

Statelessness

REST is based on HTTP statelessness, which means that a REST request or message must contain all the information necessary for the server and/or client to process the request. This means at the same time that a client does not contain any information after a response when a resource changes. A client must request the resource again for updates.

Addressability

Each resource has a unique address that can be created, requested, modified or deleted via the URL. This simplifies the generalized and standardized construction of web interfaces and the secure as well as correct exchange of resources.

HTTP verbs (GET, POST, PUT, DELETE…) are used in addition to the address.

Sample:

HTTP verb Adress Description Response
GET my-rest-api.com/v1/tasks Lists all tasks A collection of tasks
POST my-rest-api.com/v1/tasks Adds task The created task
GET my-rest-api.com/v1/tasks/1234 Gets task 1234 The created task of id 1234
PATCH my-rest-api.com/v1/tasks/1234 Updates task 1234 The updated task
DELETE my-rest-api.com/v1/tasks/1234 Deletes task 1234 The deleted task

Representation

Regardless of an address to a resource, it can be delivered in different structured representations, but all of them must be HTTP-compatible and thus text-based. So the REST API is free to deliver HTML, XML or Json…. for example, or dynamically with both.

XML

<Tasks> <!-- This is the collection -->
  <Task Id="123" isDone="false"> <!-- This is the item -->
    <Title>Buy apples</Title>
    <CreatedOn>2018-04-26T16:47+00:00</CreatedOn>
    <!-- ... -->
  </Task>
<Tasks>

Json

[ // this is the collection
  { // this it the item
    "Id" : 123,
    "IsDone" : false,
    "Title": "Buy apples",
    "CreatedOn" : "2018-04-26T16:47+00:00"
  }
}

Conclusion

REST represents an HTTP standardization for exchanging information between applications - for example, a server and a client - in a structured manner.