Overview
Application Programming Interfaces, commonly referred to by the acronym API, are programmatic interfaces which allow for software to be used as a service. An API exposes methods, objects, endpoints, or some other form of state representation and or manipulation to another piece of software for it to utilize. They are intended to connect pieces of software together.
Categories
There are 2 general categories that APIs can fall into.
Library/Framework/Module APIs
These types of APIs usually expose functions, objects, or other programming language specific representations of state and state manipulation to allow for interfacing or use of software.
Library and module APIs are usually intended for open-ended use of the program, for example a library that contains sorting algorithms and implementations. On the other hand Framework APIs are intended for strictly organized and or structured use. As the framework handles most of the heavy lifting.
Web APIs
This is what most people think of when the work API comes up. These are APIs that are exposed to the internet. They allow for software and services to be programmatically accessed from anywhere in the world through the internet.
Protocols
There are a few different ways to access APIs. Protocols help define how to access and manipulate state in APIs.
REST
REST or REpresentational State Transfer APIs follow a set of 6 constraints and are usually based on HTTP methods. REST APIs are very flexible and can return data represented in JSON or XML.
The six constraints are as follows.
- Client-Server Architecture
Client and server machines should not be strictly coupled.
This allows for better portability of the client and better scaling of the server.
- Statelessness
The server should not host session information about the client. Relevant session data is managed by the client.
This is ideal for high-volume applications as it reduces the amount of resources required by the server.
- Cache Ability
State should be able to be cached easily.
This reduces load times for the client while also reducing load on the server.
- Layered System
The system can add intermediary servers and services which can enhance performance (like caching).
This can include but is not limited to load-balancing/proxy servers, and security checking requests against policies.
- Uniform Interface
Like the name suggests, the interface should be uniform and should not significantly change how the client and server interact with each other.
There are 4 constraints on this:
Resource identification
Resource manipulation through representations
Self-descriptive messages
Hypermedia as the engine of application state (HATEOAS)
- Code on Demand (Optional)
Code can be executed on the server if needed.
SOAP
RPC
Reference
- Johnson, David Various Lectures The University of Kansas 2024