In the code for the Hello Fetch example, there is a link to the following: “https://velo-examples.wixsite.com/training-tester/_functions/randomgreeting”. I was wonderding how you would create a file like this so that it has the same functionalities as the one in the example.
Hello,
You can accomplish this by Exposing a Site API with HTTP Functions .
Here is starting point for what this endpoint may look like:
import { ok, badRequest } from 'wix-http-functions';
export function get_randomgreeting(request) {
const response = {
"headers": {
"Content-Type": "application/json"
}
};
try {
//Hardcode random responses or use third party API to translate 'Hello world!' message to appropriate randomly selected language
response.body = {
greeting: {
"language": "English",
"message": "Hello world!"
}
};
return ok(response);
} catch (err) {
response.body = {
"error": err
};
return badRequest(response);
}
}
You can either hardcode the responses and randomize the response object, or call a third party API that translates the message to the randomly selected language.