Introduction to Climacell Public API

Climacell's Public API is a powerful tool that provides real-time weather data for various purposes. With a wide range of data points and parameters, you can retrieve weather information for any location around the world.

In this blog, we will discuss how to access and use Climacell Public API using JavaScript language.

Getting Started

To use Climacell Public API, you must have a valid API key. You can get your API key by signing up on Climacell's Developer Portal.

Once you have obtained your API key, you can start using the API.

API Endpoints

Climacell API provides different endpoints for different kinds of data. Following are some of the commonly used endpoints:

  • Realtime - Provides current weather data for a specified location
  • Nowcast - Provides current and predicted weather data for a specified location
  • Forecast - Provides hourly or daily weather data for a specified location
  • Historical - Provides historical weather data for a specified location

Example Code

To use Climacell Public API using JavaScript, you can follow the steps below:

  1. Create an instance of the HTTP client to send API requests. You can use any HTTP client library for this purpose. In this example, we will use the axios library.
const axios = require('axios');
const API_KEY = 'YOUR-API-KEY'; // Replace with your API key
  1. Make an API request to the desired endpoint using the HTTP client. In the following examples, we will make requests to the realtime endpoint to retrieve current weather data for a specified location.
// Get current temperature for a location
const getTemperature = async (latitude, longitude) => {
  const response = await axios.get(
    `https://api.climacell.co/v3/weather/realtime?lat=${latitude}&lon=${longitude}&unit_system=si&fields=temp&apikey=${API_KEY}`
  );
  return response.data.temp.value;
};

// Get current weather condition for a location
const getWeatherCondition = async (latitude, longitude) => {
  const response = await axios.get(
    `https://api.climacell.co/v3/weather/realtime?lat=${latitude}&lon=${longitude}&unit_system=si&fields=weather_code&apikey=${API_KEY}`
  );
  return response.data.weather_code.value;
};
  1. Use the retrieved data to build your application, such as displaying the current weather condition and temperature on a webpage.
const latitude = 37.7749; // San Francisco latitude
const longitude = -122.4194; // San Francisco longitude

getTemperature(latitude, longitude).then((temperature) => {
  console.log(`Current temperature: ${temperature} °C`);
});

getWeatherCondition(latitude, longitude).then((weatherCondition) => {
  console.log(`Current weather condition: ${weatherCondition}`);
});

Conclusion

Climacell Public API provides powerful tools to access real-time weather data. With JavaScript, you can easily build applications that retrieve weather information for any location around the world.

Related APIs

Public APIs — A directory of free and public apis

Built by @mddanishyusuf