Let’s use web APIs!

Angela DVT
DVT Software Engineering
5 min readAug 5, 2019

Often we want to create an application with data entities so why not get predefined data from free APIs. Or simply set up your own server and create an API for continuous reuse within your Web apps. This is a fun way to make your application not only functional but also aids in keeping your Web app relevant. Don’t think of this as a majorly complicated task. Applications such as Postman can make API usage, discovery and integration, effortless and effective.

API Vector.

Article title:Free vector icons designed by DinosoftLabsWebsite title:FlaticonURL:https://www.flaticon.com/authors/dinosoftlabs

Download Postman below:

With the use of Postman I was previously able to use data from the Meetup API for my own application. I find Postman to be a very useful tool for manipulating API data in every phase of the design and development.

JSON and NoSQL.

On a server different formats of API data can be stored within a database. The data may be stored in the form of documents. A JSON document is one that archives uncomplicated data objects and compositions. JSON data is typically stored in a NoSQL database.

NoSQL databases are the an alternative to relational databases. RDBMS database systems rely on the relational modelling of data and retrieving or manipulating through Structured Query Language (SQL). All data is presented in form of tuples and categorised into relations. Whenever I think of a relational database I think of all the relational tables “holding hands” in a sense. As you can imagine this can become very complicated very quickly if you have many tables “holding hands”. Because the tables are interlinked.

My thoughts on RDBMS.

NoSQL databases are not structured in the form of tables with rows and columns, instead data is stored in a document database. I’ d like to believe that JSON data is a more convenient to work with. Previously I made use of MySQL databases, only recently being introduced to JSON data, I can potentially see JSON data becoming more prevalent. And why not eliminate complexities?

Below is the very example of what it looks exactly like:

JSON document.

Notice how simple the data structure becomes when there are no tables, columns or rows. No foreign keys, no primary keys. Just pure ease of use!

The RESTful architectural style.

Different architectural styles such as Representational state transfer or REST define restrictions which can be used for implementing services. Implementing services such as these are referred to as RESTful implementations of APIs. RESTful services permit requesting systems to acquire and manage textual representations of Web resources. A Web resource may be considered as a definition of items that can be distinguished, labeled or manipulated in various ways. In other words the principal portrayal of data is referred to as a Resource within REST terms. Through the use of resource identification, or in this case RESTful Uniform Resource Identification a referral can be made to a resource. Resources are noun phrases, resources also have properties.

Below is a simple example of a resource:

  • User Account.

A user account can have many properties.

For example:

  • Username.
  • Password.
  • Email address.

As simple as that an entity with attributes!

The Hypertext Transfer Protocol.

HTTP is used in order to request documents over the internet from a specified web server. Assuming that we already have a server setup, we are able to perform different HTTP request methods on the API. Perhaps you wish to get information in the form of JSON data, you’ll easily be able to use a GET method. GET is much like view only ,you will only be able to retrieve a JSON representation of the resource.

Basic HTTP request methods can be seen within the table below:

The modern JavaScript Fetch.

Previously we may have used the XMLHttpRequest in order to make network requests. The XMLHttpRequest requires a success and error listener. Fetch may be seen as a more desirable alternative. Unlike the XMLHttpRequest, Promises offer multi-chain capabilities enabling us to share logic across fetch requests. Code is made simple by the chaining of Promises.

Fetch offers an intelligent interface for gaining access to and re-engineering certain aspects of the HTTP requests and responses.

Request:

Example of a basic HTTP Request.

Response:

Example of a HTTP Response.

Fetch makes use of Promises as perviously mentioned, facilitating a cleaner and more streamlined API. A Promise may be seen as a representative for a value, the said value might not yet be accessible but will eventually become accessible. In other words a Promise acts as the eventual execution or failure of an asynchronous operation along with its resulting value.

Below is a typical example of a fetch method.

Fetch method.

The URL represents the address of a resource located at the server. The options parameter would allow you to specify the HTTP verb to use. For example ‘GET’. The options parameter also allows including HTTP headers with the request. The Content-Type header specifies the requested resource content type an example of a content type is application/json or text/html. Within the options parameter we can also specify a security value for authentication to the API. The default value is “omit” omit, meaning that there is no specified authentication.

Advantages of API data use.

API data is convenient to use. There are many advantages offered by APIs some of which include:

  • Raised levels of productivity
  • Effortless integration.
  • Automation of workflow management eliminating human error.

Modern options to retrieve, edit, append and create API resources are constantly being made available to us. In using these tools, applications and modern features in programming languages such as JavaScript we will be able to create comprehensive Web applications. APIs offer us a reusable form of data, keeping in mind that when our APIs are kept up to date our applications will remain relevant.

Why not explore API creation and usage yourself?

--

--

Angela DVT
DVT Software Engineering

I am a Web Developer at a company called DVT. I joined the company after requiring my degree in IT.