The Fetch API enables you to send an HTTPS request to a server from your frontend or backend code. You can use the Fetch API to communicate with an external API to access or manage data and it's awesome. With the Fetch API, you can:
- Integrate additional functionality using a 3rd-party API.
- Retrieve data from an external service.
- Submit data to an external database.
Get hands-on experience with the Fetch API on our Hello Fetch example page.
To use the Fetch API, import
wixFetch from the
Although you can use the Fetch API in frontend or backend code, it's usually best to send requests to external APIs from your backend code. This is more secure, especially if the API requires a key or other authentication, and it avoids CORS issues that can occur when sending some requests from the frontend.
The Fetch API contains two functions for sending HTTP requests:
fetch(). For simple
GET requests for retrieving a JSON object we recommend using
For more complex requests,
fetch() provides greater functionality.
The implementation of the
fetch() function differs slightly depending on whether you are using it in backend or frontend code.
The features documented here reflect the base functionality for both implementations.
However, each implementation contains additional features:
- HTTP: HTTP is a standard protocol for transmitting information between a client and server. The client (your site or a site visitor's browser) sends a request to a server (an external API) and waits for a response.
- Method: Each HTTP request specifies a method indicating the type of action being requested. For example, a
GETrequest is used for retrieving data, and a
POSTrequest is used for submitting data.
Was this helpful?