Integrate with external services through API calls
This example demonstrates how to use the `wix-fetch` API to call external APIs.
We call the external Greeting API to fetch greetings in different languages on our site.
This example demonstrates how to retrieve data with a very basic implantation of authentification. To securely implement authentification in your website project, use the Secrets Manager feature.
We added the following to our site:
The code in this file adds an onClick()
event handler to the button. The handler calls getRandomGreeting()
to get a random greeting, and then displays the response in the container.
The code in this file adds an onClick()
event handler to the button. When triggered, the handler calls getGreetings()
to get a list of all the greetings, and then displays the response in the repeater.
The code in this file adds an onClick()
event handler to the button. When triggered, the handler calls addGreeting()
, which adds a greeting using the language and greeting values from the input elements, and then displays a success notification in the container. (This greeting is added to the database of greetings used by the API.)
The code in this file calls an external API to retrieve and add greetings. We defined the following methods:
getRandomGreeting()
: Calls an external API using fetch()
to retrieve a random greeting.getGreetings()
: Calls an external API using getJSON()
to retrieve a list of multiple random greetings.postGreeting()
: Calls an external API using fetch()
with a POST
method to add a greeting to the database of greetings used by the API.Join the Wix Studio community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.
Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business. Visit the Wix Marketplace to find a trusted developer.