HTTP REST API: OpenWeatherMap Example
The hugr
GraphQL engine can integrate with HTTP REST APIs, allowing you to fetch data from external services like OpenWeatherMap. This example demonstrates how to set up a simple GraphQL schema that queries weather data using the OpenWeatherMap API.
Technical Overview
The hugr
engine implements the data source type for HTTP REST APIs - http
. Technically, http data sources are used DuckDB backend to fetch data through the special SQL function http_data_source_request_scalar
. This function allows you to make HTTP requests and retrieve data in a structured format, which can then be used in your GraphQL queries. To add HTTP RESTFull APIs to the unified GraphQL schema, the hugr
functions should be defined as http_data_source_request_scalar
calls.
The function also accessible through the hugr
GraphQL API, allowing you to query data from external REST APIs directly in your GraphQL queries:
query getCurrentWeather{
function{
core{
http_data_source_request_scalar(
source: "owm"
path: "/data/2.5/weather"
method: "GET"
headers: {},
parameters: {
lat: 35.6895
lon: 139.6917
},
body: {},
jq: ""
)
}
}
}
It uses the data source parameters to perform http requests.
Example
- Getting Started
- Manual GraphQL Schema
- OpenAPI Specification