Launch allows you to write Cloud Functions to create API endpoints.
This step-by-step guide lets you add API endpoints to a website in Launch.
Follow the steps given below to write a Cloud Function that can be used to add API endpoints to a website in Launch.
Example:
// functions/users.js
export default function handler(request, response) {
const users = [
{name: "Jack", age: "25"},
{name: "Rick", age: "28"},
{name: "Jane", age: "34"},
];
response.status(200).send(users);
}
The function endpoint is determined by its file path relative to /functions. The function runs when you visit the path: /users.
In this example, the URL of the API endpoint will be https://sample-test-api.devsampleapp.com/users. [
{
"name": "Jack",
"age": "25"
},
{
"name": "Rick",
"age": "28"
},
{
"name": "Jane",
"age": "34"
}
]