Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.

API

How to Build an API-Driven Weather App

How to Build an API-Driven Weather App

Many of today’s web backend applications obtain their data from different services. While the backend applications are running, they make requests to different APIs and present the data they obtain to the client.

In this article we will develop a Rest API that returns a Nodejs Weather client. This Rest API will fetch the weather data from a different API.

So let’s get started.

What is Weatherstack API

Weatherstack is a website that provides detailed information about the weather. It provides an API so that data and functions can be used by other application developers. Weatherstack provides a RESTful API service that allows it to query historical and forecast weather. The number of locations it serves is quite large. We need to review the API Documentation to learn about the data and functions it offers and how we can use them.

In the application we will develop, we will be obtaining weather data from the Weatherstack API.

You can find more information about the Weatherstack here here.

Building Weather API with Nodejs

We need an API key to use the Weatherstack API. After choosing a package from the Weatherstack website and registering, we get the API key.

Then we create a Nodejs project with default settings with the following command.

Now let’s add the packages that we will use in the project with the following command.

We create the “index.js” file in the project file location and paste the following codes.

Then we create the “routes” folder, create a file named “weatherRoutes.js” in it and paste the following codes.

Let’s run the application with the node index.js command and send a request to the “http://localhost:3000/api/weathers/Istanbul” url with the Postman application.

weatherstack-istanbul

As you can see in the picture above, when we send a request to the weather API for Istanbul, we get a detailed response in Json format.

Now we are requesting the url “http://localhost:3000/api/weathers/Rome” for the city of Rome.

weatherstack-rome

It’s that simple to develop an API application with Nodejs using the weather data provided by the Weatherstack API.

About author

I am a software developer who loves coding, learning new technologies, improving myself and researching.
Related posts
APIAutomationNews and Updates

How to Build A Sports Media Website Using Node.js and Sports Data API

API

How To Ensure Security When Developing APIs

API

What Should You Know About Open Weather APIs?

API

Is A Web Service The Same As An API?

Leave a Reply

Your email address will not be published.