このページのトップへ
Exposing APIs

Exposing APIs

Expose APIs to your site using HTTP-functions.

中級.png

上級

6K

出版された:

February 3, 2020

酒を楽しむ少女

によって

アンカー 1
開発者を雇う

説明例

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.

コード例

タブ1

.

タブ2

.

タブ3

.

このコードによる解決は複雑になる可能性がある。

どのように構築したか

コレクション 

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.

ページ要素

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.

使用したAPI

コード以外の例。

コード以外の例。

コード以外の例。

関連記事

開発者を雇う

Veloソリューションは強力なツールですが、自力で構築するのは困難です。経験豊富なVelo開発会社に構築をお任せください。

関連例

これは役に立ったか?

はい

|

いいえ

ご意見ありがとう!

サイトAPIの公開とアクセス

サイトAPIの公開とアクセス

APIを公開するにはwix-http-functionsを使用し、外部APIにアクセスするにはwix-fetchを使用します。

中級.png

中級

Secrets Manager

Secrets Manager

Store API keys in a secure manner using Secrets Manager.

中級.png

中級

カスタムチャートの作成

カスタムチャートの作成

JavaScriptのポストメッセージを使ってHTMLコンポーネントと通信する。

中級.png

上級

アンカー2
ページ下