What Is REST?

Basics

REST stands for REpresentational State Transfer.

It is an architectural style for APIs (Application-Program Interfaces). It focuses on element interactions rather than implementations.

REST is language-independent concept.

REST is designed for performance, scalability, simplicity, modifiability, visibility, portability, and reliability.

REST systems usually communicate over HTTP, using the verbs GET, POST, PUT, DELETE.

Concepts

Separation of Client and Server
Stateless Server Requests
Cacheable Requests
Uniform Interface (URI)

You're API can be RESTful without following 100% of the REST architecture.

Benefits

REST is built on pre-existing standards, such as HTTP, instead of making new ones.

Encryption and data transport integrity rely on pre-existing standards, such as SLL (Secure Sockets Layer) and TLS (Transport Layer Security).

Most web programmers will already be familiar with the building blocks of REST.

Disadvantages

REST is stateless because HTTP is stateless (no data is stored between request-response cycles).

REST does not support push-notifications from the server to the client. The client would have to poll the server for updates, or use some other web hook.

There is room for disagreement about which applications are "RESTful".

Architecture

REST takes a resource-based approach. You locate a resource on the server, and then update it or delete it or get some information about it.

With SOAP, the client does not choose a resource directly. The client use calls a web service method (or operation) which may set off any number of tasks before returning a value.

The basic idea of REST is that retrieving information about a resource should be as simple as invoking its URL. For example, invoking "www.techtarget.com/restfulapi/quizzes" could return the JSON "{ "quizzes" : [ "Java", "DevOps", "IoT"] }". And the URLs are designed to be human-readable.

Microservices

REST is a light-weight messaging solution appropriate to the microservices architecture.

REST over HTTP offers little more than message exchange. For instance, it does not contribute to security.

Data Format

RESTful services usually return data in JSON or XMl format. REST itself does not restrict what data formats can be used.

HTTP Methods

GET: returns the resource
PUT: saves a new resource
DELETE: deletes a resource

POST: some more complex operation

Why Use An API?

You need to communicate across networks.
You need to communicate across proxies.
You need to communicate across firewalls.
You are building a mobile app.
Terminology

URI, URL, URN

URI stands for Uniform Resource Identifier.
URL stands for Uniform Resource Locator. Example: https://a.b.com/d
URN stands for Uniform Resource Name.

URLs and URNs are both types of URIs.
API Design

Design your API before you start coding it.

Once you publish an API, you'll have clients building their code on top of yours.
The cost of altering your API goes up quickly, the more people rely on it.

Parts Of The API

Request = Verb + URI (with Query String) + Headers + Content

Response = Status Code + Headers + Content

URI

A URI is a path to a resource on your server.
Ex: api.myserver.com/people is a path to the "people" resources.

Your URIs should be Nouns. Ex: Repositories, Customers, Contracts, Books.
Leave the Verbs to the HTTP Request Verbs.

Query String

Query strings should always be optional.

They are commonly used for Formatting, Sorting, Searching, etc.
Postman

About

[Postman]

Postman is a development environment for APIs.

Features:
- Send REST, SOAP, or GraphQL requests
- Automate testing and integrate it into your pipeline
- Design and Mock expected behavior
- Generate and Publish documentation of your API
- Monitor the health of your API
- Collaborate in real-time with other developers
- Built-in version control

Make A Request

Open Postman > Click + to open a new window > Select a HTTP Verb > enter the URL > click Send