REST (Representational State Transfer) is a set of architectural guidelines for implementing an API. The principles of REST were formulated by computer scientist Roy Fielding in 2000 and have since become the dominant paradigm for implementing APIs. This is because the REST paradigm is flexible and adaptable to client requirements. Unlike alternatives it is language and framework agnostic. It works in the principle level rather than the protocol level. An API is described as “RESTful” if it implements the REST paradigm. Sinch has plenty of RESTful APIs which allow developers to leverage capabilities like SMS messaging and automated email marketing. They get their power by having REST features like the following.
Like most applications and sites on the web, RESTful APIs follow a client-server architecture. This consists of three components:
As an example, let’s look at the Sinch SMS API. Clients, which are typically Sinch customers, can access it by signing up to Sinch and receiving an API token for authentication. They can then send requests to the API through their code or using Postman.
The XMS server hosts four resources:
RESTful architecture typically contains 3 tiers.
For example, the SMS API implements this in the form of a Multi Service Layer (MSL) platform. The REST and service layers are implemented by Spring-based component called Gateway and Adapter. Gateway has the ability to queue SMS messages for processing. Adapter is specialized to process MMS messages. In the SMS API, MySQL is used to implement the data layer, allowing customer data to be persisted and retrieved for later use.
RESTful APIs are normally accessed through HTTP requests. There are 9 different types of HTTP request but the four most common are GET, POST, PUT and DELETE. For example, one of SMS API’s resources enables processing of batches of messages. This resource contains:
One of the core principles of RESTful architecture is that API resources and methods are attached to URIs called endpoints. Endpoints have the same structure as a website URL, but instead of loading an application onto your browser, they enable you to send HTTP requests to the API.
Each endpoint specifies a particular resource. For example in the SMS API the endpoint https://us.sms.api.sinch.com/xms/v1/{service_plan_id}/batches specifies the resource for sending a batch of messages. The ability to access API resources the same way you would access any other resources makes RESTful APIs an extremely powerful development tool and the backbone of modern web development.
Sinch has REST APIs for: