Calling tasks and APIs

Execute Airplane tasks or call external APIs from a view
Most views will need to make a series of network requests to populate a component with backend data and/or mutate something in the backend.
There are a few ways to fetch data from views. You should choose the simplest method that accomplishes your goal. The following strategies are listed from simplest to most complex:
StrategyNotes
Task backed componentsSome components automatically execute Airplane tasks or runbooks, handle loading and error states, and populate their own data. Recommended
Calling tasks with React hooksYou can execute an Airplane task or runbook using a React hook. You are in charge of populating the data in a component and handling loading and error states.
Calling non-Airplane APIsCall a non-Airplane API

Which data fetching strategy should I use?

If you want to execute an Airplane task in a component that integrates with tasks, such as table or button, use Task backed components.
If you want to execute an Airplane task in any other situation, see Calling tasks with React hooks.
If you want to call a non-Airplane API, use Calling non-Airplane APIs.

Queries and mutations

One important distinction to understand is that between queries and mutations. Task runs started by Airplane Views can fall in either category.
A query retrieves data and is assumed not to have side effects. Queries are executed behind the scenes by most Airplane components that rely on a task for data, such as Table or Select. Queries have intelligent behavior such as caching and automatically refetching data. As a best practice, ensure that tasks that are run as queries are lightweight and read-only as they may be run repeatedly.
A mutation creates, updates, or deletes data. It does not have any built-in refetch or caching functionality. Mutations are generally executed by an intentional interaction with an Airplane component, such as by clicking on a Button.
For more information on how to call task queries and mutations, take a look at the documentation about manually executing tasks in views.

Debugging task and runbook executions

You can use the Activity tab of the debug panel to debug task and runbook executions originating from your view.