Call APIs

There are two ways to call your APIs. Earlier, we covered auto-fetch, which automatically calls the API initially and on change. Auto-fetch is usually the go-to solution for GET requests, as you can simply use the data without thinking about how or when it is called. Additionally, it enables server-side rendering (SSR) of the requested data.

However, for most other APIs, such as POST, PUT, or DELETE, you usually want to call your APIs programmatically through a workflow action. You will find one action per API.

For most other APIs, such as POST, PUT, or DELETE, you usually want to call your APIs programmatically through a workflow action. Find one action per API.
You can also use the action above to manually refresh an API with auto-fetch

Inputs

You can declare inputs on APIs. Inputs are helpful when you want to call an API during a workflow since they let you override one or more of their values. When you select the action, you can choose which inputs to override. Omitted values will default to the value set on the API.

For example, for a weather API, we could want to fetch the weather forecast for different cities. Instead of creating one API per city, we make an input called "city" and call the API with a new value when we pick a city from a list. However, inputs are more often used for non-GET requests, like deleting a row in your database, where the row identifier is an input.

Callback events

You may notice that both the workflow action and the API itself have callback events "On success", "On error", and "On message". This is useful as you may want some standard behavior on your API, like setting or clearing error messages on the screen, but then have more specific event handling on a per-call basis.

Callback events on the API itself execute just before the action-specific events.

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code โ€” but accessible to your entire team!

Try toddle โ€” it's free!

ยฉ Copyright 2024 toddle. All rights reserved.