Expose an API using wix-http-functions
Access (consume) an external API using wix-fetch
Web modules - server-side (backend) code
Required for this example
A cold beer.
About the examples
🍻 MyApi (server/API app)
MyApi exposes an API by defining HTTP functions in the http-functions.js backend file. These functions are not called in code. Rather, they are invoked when an HTTP request, using the associated URL for that HTTP function, is received from a client app.
MyApi is essentially “pageless”. That is, the HOME page in this app is not needed for the API and only exists since a Wix site cannot exist without a page.
Important: You must save and publish your API site (MyApi) for changes to take effect on the testing and production endpoints.
🍻 MyApiClient (client app - consumes the API in MyApi)
MyApiClient uses the wix-fetch API to “talk” to the API exposed in MyApi. MyApiClient does not have any database collections of its own. Instead, it sends fetch requests to the API exposed in MyApi, which ultimately invoke the appropriate HTTP functions (endpoints) in the MyApi backend file http-functions.js.
MyApiClient uses a GET fetch to the API to retrieve a list of recipes which are displayed in a Repeater. Clicking on a recipe opens a Lightbox to display the recipe. The user can rate the recipe and a POST fetch request is sent to update the recipe’s rating in the Lightbox.
🍻 MyApiCombined (bonus app)
Important: You must save and publish your site (MyApi) for changes to take effect on the testing and production API endpoints.