hi!
serverless functions are one of my favorite tools! I use them for anything that requires a bit of server-like processing or secure calls
a few examples:
- to access an API that requires a token, I use a serverless function and add the token as an environment variable, which lets me securely get the data
- to provide a simple API, such as the Learn With Jason schedule API
- to handle form submissions
- to respond to events from other services (for example, sending a receipt whenever someone buys something from my store)
the easiest way I know of to implement serverless functions is to create a new Netlify project and add a file at netlify/functions/hello-world.ts with the following code:
export const handler = async function () => {
return {
statusCode: 200,
body: 'Hello world!',
};
};
to test locally, install the Netlify CLI:
npm install -g netlify-cli
then start the site:
ntl dev
you'll be able to call your function at localhost/.netlify/functions/hello-world
I have a post on getting started with serverless functions, a video tutorial for getting started with serverless functions, or if you want a full-blown course I have a Frontend Masters course on serverless functions