Intro to API calls
Application programming interfaces, called APIs, power the web. They serve as intermediaries through which applications can share information and extend functionality with each other. APIs are the backbone of countless software applications. There are also different types of APIs, the most popular being REST. REST stands for representational state transfer. It’s a request-based architecture that entails sending a request and receiving a response in turn.
An API call, or API request, is a message sent to a server asking an API to provide a service or information.
Developers often need to make API calls on a schedule, such as with sending weekly email newsletters or running software health checks. For these scheduled API calls, developers may have to hard-code scheduling into their applications and services to make the API requests happen regularly. Other times, developers implement third-party services like cron and Heroku to schedule jobs.
Airplane is a developer-first platform for building powerful internal applications. Airplane provides a simple, easy, and serverless way to make API calls and schedule API requests. Airplane Tasks are functions that anyone on your team can execute. A task can be a SQL query, custom TypeScript/JavaScript/Python, or wrapping around a REST API call. Tasks are the building blocks of Airplane and represent single operations such as "restart a microservice," "hit X API endpoint," or "update user email."
In this article, we'll walk through how to make and schedule an API call in just minutes using Airplane. As an example use case, we'll discuss how to schedule an API call to fetch the top headlines in Nigeria every minute using the News API REST API.
Prerequisites
Before beginning, you'll want to have the following prerequisites:
- A development machine with macOS, Linux, or Windows operating system
- Access to a web browser
- A free Airplane account
How to make and schedule API calls in three steps using Airplane
Airplane is a developer-first platform for building powerful custom UIs and workflows. You have a couple of options for hitting the APIs of other services using Airplane. 1) You can use Airplane's REST API resource to allow your tasks to connect to an HTTP service. We'll walk through how to do that in this article. 2) You can also use a code-based Airplane Task like Python or Node to write a script that calls whatever API you're looking for.
Making API calls is pretty straightforward when using Airplane. We'll cover how to schedule REST API calls in three steps in the following sections. The steps include:
- Configure REST API access
- Create a task
- Set that task to run on a schedule
Use case: The task we'll build will fetch the top headlines in Nigeria every minute using the News API REST API.
Setup
First, create an account with News API if you don’t have one yet. News API is a simple HTTP REST API for searching and retrieving live articles from all over the web. If you don't have an account, you can sign up for free on the registration page.
Take note of the API key that is generated for you after registration. You can also view this API key in your account profile, as shown below:
Next, sign in to your Airplane account and install the Airplane CLI. You can do so by following the quick steps on installing the CLI in the docs.
That's all the setup required. Let's get started building!
Step 1: Configure REST API access
In Airplane, Resources allow you to specify and connect to databases, APIs, and other external systems. You can connect to databases including MySQL, BigQuery, MongoDB, Snowflake, and Postgres. You can also create an Airplane resource to hit a GraphQL or REST API (which is what we'll be doing in this section). Finally, resources can be used to connect to messaging platforms like Mailgun, SendGrid, and SMTP.
You can then build Airplane Tasks and use these resources in them. Tasks are the building blocks of Airplane. A task represents a single operation such as "restart a microservice," "hit X API endpoint," or "update user email."
In this tutorial, we'll create a REST resource that connects to News API.
First, navigate to Settings on the navbar and click Resources under the Developer settings section. Then, click the New resource button.
Select the REST option in the APIs section to open up the New Resource form.
Provide a name for the API, for example, News API. Supply the base URL of the News API REST API, https://newsapi.org
, into the Base URL field:
Click the + Add header button to access the fields to specify header details. For this tutorial, let's add our News API API key as X-Api-Key: your_newsAPI_key
.
If you're curious, you can check out other methods of authenticating API requests to News API in their documentation.
Click the Create button to complete the process.
That's it! We added our REST API resource to Airplane so that we can use it in our tasks.
Step 2: Create an Airplane Task
Next, let's create a task using the REST resource we just set up. The task will fetch the top headlines in a country using News API.
Create a new task using the + and select the REST option. You have two options for creating a task: you can build your task from the UI or from the CLI to manage your task entirely in code.
Whether using the UI or the CLI, you'll be able to give your REST task a name and description. Let's call our task "Get Top Headlines in Nigeria." Click Continue to navigate to the next page.
On the next page, select the News API resource we created earlier. Then, we'll see a set of fields to configure an endpoint. Change the Method to GET, then add the /v2/top-headlines
endpoint to the path.
Click the + Add parameter button to add the country parameter in the URL parameters, as shown below. We can pass in ng for Nigeria as the value of the country. You can find a list of countries and their value codes on the News API sources page.
Click the Create task button to complete the process.
That's it, we finished creating a task to hit the News API REST API. Click Execute task to run the task to make a GET request to the News API.
We can also view the response for our task in JSON as well as view logs and other metadata for the run. Click the JSON button beside "Output" to see the response returned for the request in JSON format, as shown below.
If your task fails, you'll also see the response and failure error in Airplane.
That's it! We finished creating our task. Now, let's complete the final step. We'll configure a schedule to run the task on a set cadence.
Step 3: Schedule your task
Next, we’ll set the task we just created to run on a schedule every minute. This means that our task will get the top headlines in Nigeria every minute. Using Airplane, setting jobs to run on schedules is seamless.
To do this, click Schedules button on the navbar to go to the Schedules page. Then, click the New schedule button. You can also go back to your task and click the New schedule button from there.
A pop-up box will ask you to select the task to be scheduled. Let's select the task we created earlier from the list: Get Top Headlines in Nigeria. Click Next to move to the configuration page.
You can configure your schedule using the Simple configuration or using Cron syntax. Select Simple and then select Every minute. Airplane will let you know when the next three runs will happen.
We can also give our schedule a name, such as Every minute GMT+1, and a description, such as Fetch top headlines in Nigeria. Click Create schedule to complete configuration.
Your schedule is all set! You can see the recent runs that were executed below the schedule. You can also manage all your schedules centrally from the Schedules page.
To pause your schedule, click the three-dot menu icon beside the "Edit schedule" button on the top right corner of the page. You'll see a number of options including the option to pause your schedule.
Use Airplane to build powerful internal tools
In this article, we walked through how to use Airplane to make REST API calls and schedule these requests in three easy steps. While you can use Airplane's REST API resource to connect to an HTTP service, you can also use Airplane's code-based tasks like Python or Node to write a script that calls whatever API you're looking for.
Airplane is an enterprise-grade platform for rapidly building custom applications that can be shared safely. You can transform scripts, APIs, and SQL queries into powerful UIs and Workflows in minutes. In addition to allowing you to connect to APIs, Airplane supports a number of other features. The platform layers on a web UI, notifications, input validation, role-based access controls (RBAC), approval flows, audit logs, schedules, templates, and more to rapidly build internal tools.
Engineering teams use Airplane to quickly create internal dashboards and admin panels, run scripts, host cron jobs, and model multi-step processes like customer onboarding workflows.
You can sign up for a free account to try it out or contact our team at [email protected] 👋.