Needs of Web APIs in modern workflows.

As we all know, during the current era, alot of software companies rely heavily on APIs and Web Services, the question being, why is there the requirement of a completely new set of skill for a web developer and why should one care about them? To answer this question, we first need to know what API are.

What are web APIs?

API is an acronym for Application Programming Interface. Sounds exhausting, right? It won’t be in less than a few minutes, API is just a layer which is specific for one and only one, “Data”. But where did this word data come from when we don’t understand what simply an API is. API is a layer where data is manipulated, it works on networks calls. For example, someone requests a resource from a web server, there are two possible out comes in this scenario, either the request will be accepted or it will be rejected.

Lets consider, for a second that a request is accepted, the server will try to look up (GET) or create (POST) a resource, if there is any logic written to handle the request, the request made by the client (user) will return a successful response. In any other case, the response returned will be an exception or a unsuccessful response. In the first case, the HTTP status code in case of GET request will be 200 (OK!) and 201 (Created) for POST request. In the latter, we will get the response with status code of 404, not found.

Status codes

These status codes are really short ways of server to say that how the transaction of data with client has gone.

For example:

  • 100 to 199 – Informational Responses – They are returned when there is information sent or received during a network transaction.
  • 200 to 299 – Successful responses – This is a server’s way of telling a client that the request was handled successfully.
  • 300 to 399 – Redirects – It tells us where or why have we been redirected, it maybe any issues with redirections or redirection regarding logic flow.
  • 400 to 499 – Client Error – Here i servers way of telling us that we have done something wrong.
  • 500 to 599 – Server Error – In this case, server is telling that this time the issue is with the server itself and not the client.

How they work.

Now we can deduce, what a web API is. Another important thing to note here is that API are just chunks of data being sent around the server and the client. There is nothing interesting for a user to see. The question that arises here is that if the user cannot see in the web API, who are we making it for? Of course, the user does not have to see data in this form

{
   "data":[
      {
         "name":"Coding Tricks Hub User",
         "username":"CodingTricksHubTest",
         "email":"user@codingtrickshub.com"
      }
   ],
   "msg":"Data was retrieved",
   "status":200,
   "count":1
}

rather, they would see data like:

This is how an API works. It sends response back to the client in such a form that is readable by any technology stack known to man. Let it be LAMP Stack, MEAN or MERN stack, .NET Framework or any combination of technologies that can process HTTP/HTTPS Protocols.

Advantages of Web APIs over conventional web development

There are huge development benefits of web APIs over conventional web development; some of them are:

  1. They are platform independent. This is easily the most useful part of web API. This means, a single API can run on any platform, for example, in my last tutorial, we made a Web API, this API can be consumed by anyone. And by any I literally mean any device on earth that can use the internet, point being them having access to the server where the API is hosted. You want to make a mobile application? Cool, here, use this API and consume it in Java/Kotlin, React Native or Swift. I heard Single Page Application, cool, it works there too! Oh a website? They are built for them. Desktop application, it will be just fine. In short, anything with internet can use it
  2. APIs are stateless. This means there is no session or cookie data transfer which can be hijacked, when the client makes HTTP request, it has all the information it needs.
  3. APIs are fast, or blazing fast should I say? API does not have to fetch resources like images, audio or video files. It just communicates with the client via data in some lightweight data interchange format. Like JSON, XML or YAML etcetera.
  4. They are easy to learn.
  5. They can minimize the risk of exposing sensitive user data like email, passwords and information because they don’t require a database to store all the information, you can use a web service in your web app to store the user data, for example, Google/FB authentication eliminates the need of storing data locally. Payment APIs eliminate the need of storing credentials of user’s credit/debit card information.
  6. APIs support continuous workflows, for example, a frontend team can concentrate on building a beautiful UI/UX where as the backend team can create an API which can be integrated by an integration specialist where as DevOps team can handle the deployment of the application.

These are only a few advantages while there are and can be many more listed.

This will be it for today.

Leave a Reply

Your email address will not be published. Required fields are marked *