Introduction
What Is REST?
Representational state transfer, also known as REST, is a software architectural style that defines a set of constraints to be used for creating Web services. By using a uniform and predefined set of stateless operations, it allows any system to request and access the web resources.
Why REST?
REST allows web services to have faster performance, reliability and ease of access. This is all achieved by using a stateless protocol and standard operations.
The API also enables systems to easily communicate with each other, as long as they are connected to the web. This can include: 2 different computer systems communicating with each other, or a system communicating and retrieving data from a database
One of the most important uses of REST is that it allows the use of microservice, which is a very important concept as we start working with larger web services.
Learning REST
How It Works
The REST API is mainly composed of requests which is a way for the web service to communicate with the servers or other web services. Once a request has been initialized by the web service, the request is then sent to the server, which will then act accordingly to the request method that was sent. Once the server has finished the request, it will then return a service code and a response body if needed.
A regular REST request will consist of four things: the endpoint, the method, the headers, and the data.
- The endpoint is the URL you are requesting for.
- The method is the action you wish the server to act upon, the commonly used methods are the HTTP methods.
- The headers are used to provide information to both the client and the server.
- The data is the request body, and it contains the information you wish to send to the server
Commonly used HTTP methods are:
-
POST: Creates a new resource at the end point.
-
GET: Retrieves a representation of the data in the response body.
-
PUT: Updates known resources with the new data from the request body. If the resource does not exist, it will create a resource with the data from the request body.
-
PATCH: Modifies a known resource with a set of instructions.
-
DELETE: Deletes a known resource.
HTTP Methods
Online Tutorials
A Guide to REST Using Nodejs and Javascript
The Complete Guide to Build RESTful APIS - Udemy
Learn Rest With LinkedIn
Using Rest With Spring
Testing
There are multiple ways to test your RESTful program. Here are some suggestions: