This article shows a sample flow that calls an HTTP function using the http-functions module.
import { ok, notFound } from "wix-http-functions";
import { members } from "wix-members.v2";
export async function get_member(request) {
try {
// Get member data.
const member = await members.getCurrentMember();
return ok({ member });
} catch (error) {
// Handle error.
return notFound({ error });
}
}
import { OAuthStrategy, createClient } from "@wix/sdk";
import { functions } from "@wix/http-functions";
// Create a client.
const client = createClient({
auth: OAuthStrategy({ clientId: "{YOUR_HEADLESS_CLIENT_ID}" }),
modules: { functions },
});
async function getCurrentMember() {
try {
// Call your HTTP function.
// Use the get() method
// because the HTTP function has the 'get' prefix.
const response = await client.functions.get("member");
const data = await response.json();
const { member } = data;
// Handle member data.
} catch (error) {
// Handle error.
}
}
getCurrentMember();