Build your own Serverless Functions

Here’s how you can build your very own first serverless functions or if you wish to try another approach other than AWS Lambdas and/or Azure Functions.

- TL;DR

  • Serve simple applications using serverless architecture provided by Vercel (former Zeit) following the documentation.
  • Choose your language as follows. I myself chose Node.js (with TypeScript).

- Supported Languages

- Setup your first endpoint

import { NowRequest, NowResponse } from '@vercel/node'

export default (request: NowRequest, response: NowResponse) => {
const { name = 'World' } = request.query
response.status(200).send(`Hello ${name}!`)
}
  • Vercel’s Serverless Functions follows this simple convention: put your endpoint file under the folder /api and it is all set. e.g. endpointname.ts => /endpointname
  • LINK TO MY PROJECT:

https://github.com/olavoparno/translate-serverless-now

- How do I serve it at Vercel?

  • You could download Vercel’s examples repository and cut your slack from it or just start your very own git (GitHub recommended) managed project.
  • After you have logged in Vercel’s system, you can import your previously created project.
One could also just import from a template
  • From now on it is pretty much done. Just make your adjustments such as environmental variables, NPM scripts, root folder, setup your domain and setup your branch deployment trigger.

- Integrations

  • Vercel also provides a bunch of incredible integrations such as analytics and monitoring tools, which you can mostly use free of charge.

- Bonus

  • There is also another incredible serverless tool for cache management (Redis), that is, lambda.store. Wait, what? Serverless Redis? Read more at Serverless Model

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store