APIs in Next Js: Explaining REST API & SOAP API
The only term that has confused me throughout my programming career is the term APIs (Application Programming Interface), we have heard that APIs connect 2 or more applications!
Wait, wait, wait… from where the word application comes from, I don’t even have one? That is the question that beginner programmers always get confused with, “Actually, we are building a Web Application, (web application is the one with which users can interact like, upload their data).
If I want my website to communicate with a database (mostly Postgres in the case of Next Js), the database is another application, and we make APIs to perform CRUD operations (Create, Read, Update, Delete) in our application; Web Application.”
As we have the clear concept of:
1. What a Web Application is? and
2. What APIs do?
Let’s start with the type of APIs:
1. HTTP methods (GET, POST, UPDATE, DELETE).
there are many other than them as well but, in this blog series, we’ll be talking about them.
2. REST API: REST API or Representational State Transfer API, scary name indeed but, its working is simple, “It makes a connection between the client and the server and as soon as the server responds, it closes the connection”. There are some important points to note about REST API:
1. It returns data in JSON (JavaScript Object Notation) format.
2. It doesn’t encrypt data or has some special standard to send a message to the server.
Let’s elaborate on these points with an image:
Please bear the theory with me, BTW these are the questions mostly asked in programming interviews.
3. SOAP API: Simple Object Access Protocol, the name contains the word simple but, it is more complex than REST API, so let’s see how it works, REST API makes a connection and breaks it as soon as the server responds but, “SOAP API maintains the connection and the state of the client, it also cache’s the data at the server side.”
Some important points to note about the SOAP API:
1. It returns data in XML format.
2. It encrypts data, standardize it according to SOAP protocols using XML, and then sends it to the server.
Let’s elaborate on these points with the help of an image:
Now let’s compare the working of both of them through an image:
I have a lot to say but, it might be hard for you to digest all at the moment, so see you in the next part of this blog series (APIs in Next Js).