Calling non-Airplane APIs

While views make it easy to integrate Airplane tasks using Task backed components or Manually executing tasks, there may be times when you want to call a non-Airplane backend API.
It's easy to create a small Airplane task that calls an API. By wrapping the API call in an Airplane task, you can utilize Task backed components which provide automatic data fetching, loading and error state.

Rest task

The easiest way to call an API via Airplane task is by creating a REST task. Follow REST getting started to deploy a REST task that calls your API.

JavaScript task

Follow the Getting started guide to create a JavaScript task. Include any Parameters that your API call needs.
The body of your task should look something like:
javascript
Copied
1
const endpoint = "https://catfact.ninja/fact";
2
3
export default async function (params) {
4
const response = await fetch(endpoint);
5
if (!response.ok) {
6
throw new Error(response.status);
7
}
8
9
const responseData = await response.json();
10
// The catfacts API returns a response of type { fact: string }.
11
return responseData.fact;
12
}

Call the API directly from your view

If you do not want to wrap your API call in an Airplane task, you can call the API directly from your view using the built in fetch API or another data fetching library.
Any secret API keys or other sensitive authentication pieces should not be included directly in a view.