"API" may be one of those acronyms where it is said more than it is understood. This quick overview is intended to help anyone who is fairly new to API's get a quick grasp of what an API is and their different variants.
At a basic level, an API (Application Programming Interface) is a method of passing information into a program, to get a desired result back. A simple example of this is typing a math problem into a calculator.
There is a certain way you write the request, and you have an expectation of how the response will look. "Four" (string) would technically be a correct response to the above question, although not the format you’d expect.
response: 4 //integer
response: 'Four' //string
response: '4' //string
Usually each request is made to a certain endpoint like
https://domain.com/directory/filename and you
POST parameters to the endpoint such as a start date, an end date or an ID of some kind. The endpoint is programmed to expect these parameters and will return the results in an expected/documented format.
The following endpoint call could be used to get all of the sales in January 2022 for a product with an ID of 123.
The response could return all the rows for each sale of product 123, customer names, purchase dates, discounts etc.
Need an answer to another question? Adapt the endpoint logic or create another endpoint.
Different API variants
- SOAP APIs (Simple Object Access Protocol): An XML-based protocol that is good for transferring a lot of information at once.
- REST APIs (Representational State Transfer): A stateless protocol which doesn't require server-side sessions
- GraphQL (Graphical Query Language):