DEV Community

Cover image for The Beginner's Guide to Understanding an API: Part 2
Martins Oloyede
Martins Oloyede

Posted on

The Beginner's Guide to Understanding an API: Part 2

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 to have an idea on APIs.

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

types of apis image

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>
Enter fullscreen mode Exit fullscreen mode
  • 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" },
Enter fullscreen mode Exit fullscreen mode

Differences between Soap and Rest

  • Soap: It is driven by Function.

    Rest: It is driven by data.

  • Soap: Since SOAP is a protocol, it follows a strict
    standard to allow communication between the client and the
    server.

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

  • Soap: It is difficult to implement and it requires more bandwidth.

    Rest: It is easy to implement and requires less bandwidth such as smartphones.

Differences between JSON and XML

  • Json: It is JavaScript Object Notation.

    Xml: It is extensible Markup Language.

  • Json: Focuses mainly on Data.

    Xml: Focuses mainly on Document.

  • Json: Supports only text and numbers.

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

  • Json: It has low security.

    Xml: 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 on freecodecamp that can teach you on how to test api endpoints on the Postman application.

api endpoints img

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.

Top comments (4)

Collapse
 
willreadjennings profile image
Repeat-or

Agreed! This is really great. Thanks!

Collapse
 
devmayor15 profile image
Martins Oloyede

Yeah thank you

Collapse
 
ernest2026 profile image
Ernesto

Nice, this is very helpful

Collapse
 
devmayor15 profile image
Martins Oloyede

Thanks Ernesto