![]() |
What is a Web API? |
Hello Everyone, As a web developer, you will often come across the term Web API. In this article, we will discuss what is a web API, when and why to use a web API. So, without delay lets start.
Introduction
API stand for Application Programming Interface, is a way to communicate between two application. Application can request or exchange information using some set of rules defined in it.
What is a Web API?
Web API is also an API, used to communicate between two application over web. It uses HTTP protocol to request or exchange information. Web APIs are commonly used to enable the interaction between web applications, mobile apps, and other software components.
In a traditional web application, when a client (such as a web browser) sends a request to a server to perform an action, like saving user information, the server typically processes the request and returns an HTML view as a response. This HTML view contains the content and structure of the page that the browser should render.
On the other hand, with web APIs (Application Programming Interfaces), the server provides data in a format like JSON or XML rather than a fully formatted HTML page. This allows for more flexibility in how the client (which could be a web browser, mobile app, or another server) consumes and displays the data. The client can then manipulate and integrate this data into its own user interface.
For example: Suppose you want to create a weather application. For that you need real time information regarding the temperature, humidity, current weather info etc. to display them in your application. You don't need to build infrastructure to measure weather details rather you can use data from a climate data provider. For that you need to integrate their web API provided. This is the example for a use of a web Api. You can integrate this API in any type of application like web, mobile, desktop etc.
Web API is not limited to a particular system. Web APIs are designed to facilitate communication and interaction between different software over the web, allowing them to work together regardless of the underlying technologies, platforms, or programming languages.
Why Web API?
To discuss the use of web API, let us understand by using a most useful example.
Suppose, you're developing a web application for you or your client, where you've used the traditional way to develop a web application. Here traditional way refers to the development of web applications using a server-centric architecture, where much of the processing and rendering of content occurs on the server side. Your web application is running successfully on web browsers. But then suddenly you want to develop a mobile and desktop application as well. Now, the problem will arise that we have to recreate the business logic for each platform such as mobile, desktop as well. It will be difficult to manage when any changes come. For that, we've to update each application logic deployed for each platform.
What is the solution?
The solution is simple. To handle such type of situation, Web API is the best solution.
By using a web API, you decouple the front end (mobile and desktop applications) from the back end (server-side logic). This separation allows for easier maintenance, updates, and scalability. Changes made to the business logic on the server side can be reflected across all platforms without the need to modify each application individually.
Let's understand this with the above example. Now, we've created a web API for our backend implementation (server-side logic). We can call that web API to fulfill the server-related task. Same API will be called from web, mobile, desktop application as well as other software components to fulfill the server related task. Every time any server-related task comes, we just need to update in one place i.e. inside our web API implementation. That's it.
Here are some common types of architecture used in web APIs:
- REST
- SOAP
- GraphQL
- RPC
Commonly, REST is used the most due to its simplicity. We'll discuss REST architecture in the later sessions.
Here are some common terms used in Web API:
- Endpoint: An endpoint is a specific URL or URI that represents a particular function or resource. Endpoints define the different operations that can be performed, such as reading records/a record or creating, updating, or deleting a record/records.
- HTTP Methods: HTTP methods are typically used to define the type of operation used in a resource. Common HTTP methods used:
- GET (To retrieve data)
- POST (To save data)
- PUT (To update data)
- DELETE (To delete a data)
- Request : Sending a request to a server via web or mobile app to perform an operation. The server processes the request based on the operation represented in the endpoint.
- Response: After processing the request by the server it will return the result in the form of response. It will return the response in any form such as JSON, XML, etc. instead of an html view.
Here is a simple example of Web API:
![]() |
Web API Request and Response Example |
When to use web API?
Here are some scenarios where using web API is best solution:-
- Dynamic content update: If you have some dynamic content that needs to be updated regularly. you could use a simple API to fetch that content from a server. This can be useful for things like news feeds, weather updates, or any data that changes frequently.
- Update data without page refresh: There is some scenarios you want to update data for a web page without reloading the whole page. Web API helps us update the data without reloading the whole page. This will improve user experience on that web application.
- Developing apps for multiple platform : If you want to develop an app for multiple platform such web, mobile, desktop etc. Web API is the best solution for the server-side processing task.
- Platform independent services or Data sharing services: When you want to develop a platform independent service, which can be used by any platform or services and can be accessed anywhere in the internet. Web API is the best solution. Weather API is an example.
- IoT (Internet of things): IoT devices can communicate with the server using web API to exchange data.
Conclusion
If your requirement is to create a application (having server side logic) for multiple platforms or want a decoupled application or want to update data without the full page reload or want to create services that can be consumed by any application, then my friend using web APIs in the backend will be the best solution. It will reduce cost, and time and is easily maintainable.
This is all about web API my friends.
In the next article, we'll discuss on how to create a web API using ASP.NET core. Here is the link to Create a Web API using ASP.NET Core.
Kindly share your experience with the above article, if the above information is useful for you or not. We're waiting for your feedback.
See you in the next article.
Comments
Post a Comment