API
Application Programming Interface (API) is a way for two or more applications/programs to communicate with each other.
With APIs, an application can easily be accessed via multiple canals: web interface, CLI, scripts, etc.
For example, in a service-oriented architecture, web services are a type of API which use the internet as network.
Types
- Open APIs: publicly available, anyone can access it
- Partner APIs: used to collaborate between business entities
- Internal APIs: private APIs, not exposed on a public network (or, at all)
- Composite APIs: combination of different data and services APIs
Protocols and architectures
REST
Representational state transfer (REST) define constraints and standards to assure data consistency in web applications, especially APIs.
Constraints
- Client-server: enforces the separation of concerns between the UI and the data.
- Stateless: no session is stored by the server, the client's request contains all information necessary to fulfill it.
- Cache: response is labeled has cacheable (or not), so the client can reuse it.
- Layers: client doesn't know if it's connected to the end-server or middlewares.
- Code on demand (optional): extend or customize functionality of client by transferring code
- Uniformity: 4 constraints ensure a uniform interface
- Identification of resources, in a clear and unique fashion
- Manipulation of resources, by the use of representations
- Self-descriptive messages, by providing exhaustive information
- HATEOAS, to dynamically serve and discover related resources
Resources
- Usually in JSON or XML format
- Can be…
- Static (post, article, …)
- Dynamic (weather data, satellites, …)
- Intangible (stock prices, …)
- Material (vending machine, dispenser, …)
- URL access
- Nested:
GET Nested: GET /api/posts/10/comments
- Flat: `GET /api/comments?postID=10``
- Nested:
SOAP
(WIP)
RPC
(WIP)
Resources
- standards.rest – Collection of specifications for REST APIs