top of page
Exposing APIs

Exposing APIs

Expose APIs to your site using HTTP-functions.

Intermediate.png

Advanced

6K

Published:

February 3, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example, we exposed two backend endpoints:

  1. An endpoint that receives a POST request to upload a new image to a specific collection.

  2. An endpoint that receives a GET request to get a random image out of a specific  collection and returns it.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Collections 

For this example, we created a database collection called “images” that stores image URLs. The POST and GET requests upload and retrieve images from this collection.

Page Elements

Note: We added functionality to our site that works as a playground for testing the HTTP-functions. You would normally make the HTTP requests from an app outside your Wix site.

 

In our site we added the following page elements:

  • Two Buttons

  1. getImageButton - calls the GET API.

  2. uploadButton - calls the POST API.

  • Input element: input1 - Enter an image URL to upload.

  • Image element: image1 -  Holds and presents an image from the collection.

  • Two Text elements

    1. successText - Success message on upload.

    2. failureText - Failure message on upload.

​​

Backend Code

We created 2 backend files:

 

  1. http-function.js - exposes the API endpoints that handle the incoming POST and GET requests.

  2. fetch.jsw - a web module that consumes your site’s functionality by reaching the endpoints for your APIs.

    As noted above, these calls would normally take place outside your website and are included in the example to provide a playground for the HTTP-functions.

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Expose and Access Site APIs

Expose and Access Site APIs

Use wix-http-functions to expose an API, and wix-fetch to access an external API.

Intermediate.png

Intermediate

Secrets Manager

Secrets Manager

Store API keys in a secure manner using Secrets Manager.

Intermediate.png

Intermediate

Create a Custom Chart

Create a Custom Chart

Use JavaScript post messages to communicate with the HTML component.

Intermediate.png

Advanced

Anchor 2
bottom of page