How to Access or Test Web APIs

7 Ways to Access A Web API

API(application programming interface) are a great alternative for communicating and interacting with softwares and applications. In this tutorial we will be learning about how to access and test a web API.

A Web API is a form of API that usually utilizes the REST architecture style. It uses the various HTTP request methods to retrieve and process data over the internet.

In most cases when people are referring to APIs they actually mean Web API or REST APIs.

Let us see the various ways we can access and test an API we are building. The various ways can be classified into 4 main groups.

  1. Browser Based: involves the use of any internet browser such as Chrome,Firefox,Edge,Brave,etc.
  2. Command Line Based: involves the use of a cli tool in your terminal ,eg curl.
  3. Rest Client Software Based: involves the use of desktop apps built specifically for access and testing APIs.
  4. Language Specific Based: every programming language have their own package for accessing the internet and APIs.

The basic endpoint and url we will be using will be http://127.0.0.1:5000/api/v1/books

The 7 Ways include the following

Browser

You can use any web browser to access an API by passing in the endpoint or url into the search bar or url input section in every browser. This involves the use of browsers like Chrome,Firefox,Edge,Brave etc.

Curl

This is a command line based approach whereby you use a tool called curl.

curl -i http://127.0.0.1:5000/api/v1/books

Wget

wget http://127.0.0.1:5000/api/v1/books

Postman

There are several REST Client software that we can use to test and access an API when we are building and designing one. The most commonest one is Postman. Postman can be used as a stand-alone desktop app or a chrome or firefox extension. It is quite versatile with a lot of features.

Insomnia

This is an alternatives to Postman but quite simple yet powerful with some interesting features.

Postwoman

This is an online service or platform for working with APIs. It acts like Postman but in the cloud or browser. Hence you will need internet connection to utilize it.

Using Other Languages
Python Requests

Request – one of the most downloaded python packages can be used to access a web API. It is a great tool for working with APIs.

import requests
requests.get(“http://127.0.0.1:5000/api/v1/books”).json()
Julia HTTP

Just as we have requests – a python package for access web APIs and making HTTP request, even so almost every programming language has a package or library for doing such an activity. Let us see an example with Julia.

using HTTPr = HTTP.request("GET","http://127.0.0.1:5000/api/v1/books")println(r.status)println(String(r.body))

You can also use Javascripts, Golang etc to achieve the same result.

These are some of the ways you can access and test a web API.

You can also check the video tutorial below for more.

Check Out Our Courses

Building ML Web Apps(Mega Course)

Building ML Web Apps in Python(Udemy Course)

 

Thanks For Your Time
Jesus Saves

By Jesse E.Agbe

 

Leave a Comment

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