Introduction to API
26 August, 2023
0
0
0
Contributors
What is API?
API stands for Application Programming Interface. It helps code to talk with other code. Nowadays APIs are the basic building blocks of modern software.
API allows various services, resources, and data across organizations, applications, and devices.
How do APIs work?
API architecture is usually explained in terms of client and server. The application sending the request is called the client, and the application sending the response is called the server.
Imagine Raj goes to a restaurant and tells the waiter he wants to order Samosas. The waiter takes Raj's request and goes to the kitchen to fetch the Samosas. Once the Samosas are ready, the waiter brings them back to Raj.
In this scenario:
- Raj represents a client, like someone using a website or a mobile app, who is making requests to get something.
- The waiter represents an API, which is like a service that can take requests from clients and provide them with what they asked for.
- The kitchen is like a server, which is where all the necessary stuff is kept.
Now, let's talk about an "Endpoint":
When Raj goes to the restaurant, he looks at the menu to decide what he wants. The menu is like an API's collection of services. Each dish listed on the menu is like an "endpoint" in the API. So, if Raj chooses to order Samosas, he's actually selecting an "endpoint" that corresponds to the Samosas dish. An endpoint is a specific part of the API that does a particular thing, just like how each dish on the menu does something different.
So, in the context of an API, an endpoint is like a specific item on the menu that you can order, and it represents a particular function or piece of information that you can request or interact with.
Why to use API?
- API is fast & scalable.
- Using API reduces the time of building own API.
- It provides various features.
- API can be public(for all), private(organisations) and partner(b/w partner organisations)
Types of API
- Hardware API - Hardware API establishes the communication between hardware and OS / Software. Example: camera with software.
- Software Library API - Software APIs are the libraries we use in our programming. Example:
setTimeout()
API provided by the browser. - Web API - Web API is over a network. Using Web API, anyone can fetch real-time data. Example: Weather API.
Architectures
- REST (Representational State Transfer)
- GraphQL
- WebSockets
- webhooks
- SOAP (Simple Object Access Protocol)
- gRPC (Google Remote Procedure Call)
- MQTT (MQ Telemetry Transport)
REST API
REST API architectures are the most popular and widely used in applications. REST stands for Representational State Transfer. When a client request is made via a RESTful API, it transfers a representation of the state of the resource to the requester or endpoint. This information, or representation, is delivered in one of several formats via HTTP: JSON (Javascript Object Notation), HTML, XLT, Python, PHP, or plain text. JSON is the most generally popular file format to use because, despite its name, itβs language-agnostic, as well as readable by both humans and machines.
Something else to keep in mind: Headers and parameters are also important in the HTTP methods of a RESTful API HTTP request, as they contain important identifier information as to the request's metadata, authorization, uniform resource identifier (URI), caching, cookies, and more. There are request headers and response headers, each with its own HTTP connection information and status codes.
About HTTP methods
In HTTP methods, 'headers' and 'parameters' play crucial roles. They provide essential details about the request, such as metadata, authorization, and more. There are 'request headers' and 'response headers,' each carrying its own information and status codes.
curl vs. Postman
Before Postman, the common way of using was command line tool (Terminal) for making HTTP requests using the curl command. It's used still today but has a lot of limitations.
Whereas Postman is a user-friendly tool that shows a response, status, and response time, clean with colored text. It has the features of saving responses and organizing requests.
Conclusion
APIs connect software, like friends sharing info. REST is common. Postman simplifies.
Follow for deeper tech insights! π
software
api
web
developer
webdeveloper
development