In this thread, I'll tell you all you need to know about Application programming interfaces (APIs).
P/S: If you find this thread helpful, kindly retweet 🙏
⬇️
🔹What is an API?
An API (Application programming interface) is simply the set of rules guiding how a client browser communicates with a web server to exchange data.
Three parties to note are:
- Browser (Client)
- Server (Back-end)
- A network (the Internet)
When we talk about APIs, we talk about requests and responses. A client makes a request to a server for data (HTML page or json data) over a network (The internet) and the server responds with the data.
The data transmitted to and fro are stored in something called Headers.
REST API: This lets you put and pull data from a database.
Four actions in REST APIs includes:
GET: This method retrieves data from a database
POST: This method inserts data into a database
PUT: This method updates an already existing data.
DELETE: This method deletes data
The browser and server, both possess APIs for initiating and maintaining communication with each other. For the browser, we have the built-in fetch API.
This snippet displays how a browser makes an Xhr request with it:
N/B: The parameter passed to fetch must be url to the data
For the server, which can be typically set up with any server side framework, such as Express.js in JavaScript, this how the typical API looks like:
IN SUMMARY
The web browser (client) makes a request and a web server responds with data, or an error message with status codes.
The data is transmitted in two popular forms, JSON and XML.
JSON is the most widely used. So, to be able to transmit data, you must parse it to JSON
I have a cleansheet on all the API request/response properties and methods, middlewares and handler functions used by the Express API:
VARIABLES
- Variable names are case sensitive (name and NAME are
different variables)
- Must start with a letter or an underscore
- Can have numbers but must not start with one
- Python is loosely-typed (you don’t specify the type when
declaring a variable.
FUNCTIONS
- In python, functions are defined with the def keyword.
- Indentation is used instead of curly braces.
- A colon is placed after the parameters.
- No semi-colons.
🌟 2: #null essentially means "no data", empty, nada. #undefined means data has not been explicitly defined or declared. #boolean evaluates to either true or false. #numbers are digits between 0-9, #strings are characters enclosed within double quotes