RESTful APIs

RESTful APIs

What is an API?

API means Application Programming Interface. I know, it's a lot to take in, took me a while to understand but I will try to break it down to basics. The starting point to understanding what an API is, is to understand the distinction between servers and clients.

In basic English, servers are computers/applications that serves data to other computers/applications. Clients are the other computers/applications that requests data from the servers. This allows transfer of data from different clients to a server and vice versa. Most times than not, servers and clients reside on different computers. In a simple web development scenario, your browser sends a request to a remote server somewhere and the server responds to the request sending some data.

Now that you understand the distinction, in the context of web development, the interface referred to in the meaning of API is the server interface. The layer or interface that allows clients interact with servers is what is called an API. That means creating an API is like creating an interface that allows the client to communicate with the server.

Now that you know what an API is, the next question is what is a REST API.

What is REST?

REST means REpresentational State Transfer. It is a software architectural style and it defines certain constraints that are used when creating web services.

What is REST API?

Or RESTful API, its is an architectural style for designing APIs. This means that while you are building your API there are certain constraints defined by REST that you are to abide by, to make the API RESTful.

Some REST API Fundamentals

Architectural Constraints: There are 6 constraints in all but the sixth constraint is optional. They include:

  1. Uniform Interface

  2. Stateless

  3. Cacheable

  4. Client-Server

  5. Layered System

  6. Code on Demand (optional)

You can read more on the constraints here

Protocol: The architechtural style can be used over a lot of existing protocols but when it is used for web services or APIs, it's usually used over HTTP protocol.

Naming Convention: It's important that when you are building your API, you should pay attention to how you name your resources. Especially when you are building an API for public consumption, your resources should have short, descriptive and readable address. It makes it easier for everyone to work with.

HTTP Methods: Make use of standard and appropriate HTTP methods. For cleaner interface, you can create resource address that support multiple HTTP method operations.

Further Leisure Reading on REST API

What is an API? In English, please.

What is a REST API