The Beginner's Guide to Understanding an API: Part 2
Tags: webdev, programming, tutorial, computerscience
Published: 2022-01-13 23:07:32

In the last article, we discussed what an API is, the engine behind an API, the benefits, types, what are endpoints and the major request methods we have. 


You can review it [here](https://dev.to/devmayor15/the-beginners-guide-to-understanding-an-api-52m3) to have an idea on APIs.


Now we can collect everything that we learned together and discuss more on API.


![types of apis image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ure8llplq2psy30ojcli.png)

## Web Service APIs


Before we discuss about what a web service API is, let's learn what what a web service is.


The term Web service is either: a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web, or a server running on a computer device, listening for requests at a particular port over a network, serving web documents.

Apart from the main web APIs, there are also web service APIs:

- Rest

- Soap

- XML-RPC

- JSON-RPC


The following are the most common types of web service APIs:


- Rest(Representational State Transfer): REST is a set of architectural constraints, not a protocol or a standard like other web services. API developers can implement REST in a variety of ways.
     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. 


- Soap(Simple Object Access Protocol): This is a protocol that uses XML as a format to transfer data. Its main function is to define the structure of the messages and methods of communication.

Today, it's mostly used to expose web services and transmit data over HTTP/HTTPS.

It also uses WSDL, or Web Services Definition Language, in a machine-readable document to publish a definition of its interface.


- XML-RPC: This is a protocol that uses a specific XML format to transfer data compared to SOAP that uses a proprietary XML format. 

In XML-RPC, a client performs an RPC by sending an HTTP request to a server that implements XML-RPC and receives the HTTP response.

It is also older than SOAP. XML-RPC uses minimum bandwidth and is much simpler than SOAP. Example

```
<employees>
  <employee>
    <firstName>Martins</firstName> <lastName>Oloyede</lastName>
```


- JSON-RPC: JSON-RPC is a remote procedure call protocol encoded in JSON. It is similar to the XML-RPC protocol, defining only a few data types and commands.

JSON-RPC allows for notifications (data sent to the server that does not require a response) and for multiple calls to be sent to the server which may be answered asynchronously. Example


```
{"employees":[
 { "firstName":"Martins", "lastName":"Oloyede" },
```


## Differences between Soap and Rest

- <u>Soap:</u> It is driven by Function.


     <u>Rest:</u> It is driven by data.


- <u>Soap:</u> Since SOAP is a protocol, it follows a strict 
   standard to allow communication between the client and the 
   server.

     <u>Rest:</u> REST is an architectural style that doesn’t follow any strict standard.


- <u>Soap:</u> It is difficult to implement and it requires more bandwidth.

     <u>Rest:</u> It is easy to implement and requires less bandwidth such as smartphones.


## Differences between JSON and XML

- <u>Json:</u> It is JavaScript Object Notation.

     <u>Xml:</u> It is extensible Markup Language.

- <u>Json:</u> Focuses mainly on Data.

     <u>Xml:</u> Focuses mainly on Document.


- <u>Json:</u> Supports only text and numbers.

     <u>Xml:</u> Supports various types of data for example text, numbers, images, graphs, charts etc.

- <u>Json:</u> It has low security.

     <u>Xml:</u> It has high security.



## How to start using an API

1. Get an API key
2. Test API endpoints
3. Create your app


## 1. Get an API key

An application programming interface key is a unique identifier used to authenticate a user, developer, or calling program to an API. In order to get an API key, you need to somehow register with the API server and enter your identity data.


This can be a username, email, and password; Google, Facebook, or Github account.

## 2. Test API endpoints

After we receive the API key, we can refer to the API endpoints (according to the rules in the documentation) to check if everything works as we expected. For this, we can use a REST client like Postman.


Here is a [video](https://www.youtube.com/watch?v=VywxIQ2ZXw4) on freecodecamp that can teach you on how to test api endpoints on the Postman application.



![api endpoints img](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ek2w8j8ovexofssmgde6.png)

## 3. Create your app

After we tested all endpoints and read through the API documentation and it worked as we expected, then we can start creating the application, including calls to the API.

## Conclusion


APIs are an integral part of the modern development ecosystem. Having spent a relatively short period of time studying them, you can use them to widely extend the capabilities of your own application.


Thank you for reading this article. Watch out for the next one on - How to use an API in javascript.

Reach out to me via:
- Twitter: @devmayor_
- LinkedIn: Martins Oloyede.