top of page

REST API to SQL Database Data Pipeline

Watch video

You will be explained how to connect weather conditions updates to SQL Database.

Join Jane from inanalytics.io in a brief video as she explains REST API Integration, based on weather data to Azure SQL Database pipeline example.

Thanks to the streamlined JS API, only two short JavaScript functions are required.
Write them to interact with https://openweathermap.org/, retrieve the weather forecast for a city (e.g., Kraków), and log the data into the Azure SQL Database Server every minute.

  • onStartup

  •  

    InDriver.import("RestApi");

     

    RestApi.defineRequest('krakow','{"url":"https://api.openweathermap.org/data/2.5/weather?appid={your_app_id}&q=krakow","timeout":5000, "type":"get","headers":{"ContentTypeHeader":"application/json"}}');

    InDriver.installHook(60000);

  • onHook
     

  • RestApi.sendRequest('krakow');
    if (RestApi.isSucceeded()) {

            let ts = InDriver.hookTs();

    const data = RestApi.getData('krakow');

    InDriver.sqlExecute("azureserver", "insert into public.weather (source, timestamp, data )
    values ( 'krakow','"
    +ts.toISOString()+"',$$"+data+"$$);"

    }

    This is what it looks like in InStudio.

    InStudio with configuration for Data Pipeline - RestApi JSON Weather Forecast Data to SQL Database

    Results

    Every full minute (synchronized to your computer's clock), a new row will be inserted into the Azure SQL Database Server. This row includes the 'source,' 'timestamp,' and 'data' columns, containing the current weather data in JSON format retrieved from https://openweathermap.org/.

    select source, ts, data from public.wheather

    order by timestamp desc limit 1;

    source

    ts

    data

    2023-10-04
    13:41:00+00

    krakow

    Json data presenting current weather conditions, received via RestApi from openweathermap.org and logged to sql database

    Benefits of using InDriver in this example:

    • Simplicity and Minimal Effort
      All you need to do is install InDriver, click 'Add new task,' input the two functions listed above, and then click 'Save & Restart.'

    • Stability
      InDriver ensures 24/7 availability by automatically reconnecting in case of RestApi or SQL connection failures.

    • Scalability
      You can install multiple InDrivers on various machines, and each InDriver can run multiple tasks concurrently.

    • Manageability
      Managing InDrivers is a breeze with InStudio. You can remotely check their availability, monitor errors and logs, update configurations, and edit scripts.

    • Minimal costs
      InDriver can perform such tasks an unlimited number of times, capturing data for thousands of cities, and you only pay once for the annual plan.

    bottom of page