Building an API with TypeScript, AWS Lambda and endpts
In this article, we will learn how to build and deploy a serverless API with AWS Lambda and TypeScript using the endpts platform.
There are a number of steps that go into deploying a TypeScript API to AWS Lambda:
- Transpiling the TypeScript code to JavaScript so that it can be executed by Lambda's Node.js runtime
- Minifying, bundling, and performing code-splitting on the transpiled code to generate an optimized bundle for Lambda
- Packaging and deploying the bundle and dependencies to AWS Lambda
- Wiring up the Lambda function to an API Gateway endpoint so that it can be invoked over HTTP
When it comes to automating the deployment and configuration of the Lambda and API Gateway, there are quite a few options to choose from. For example:
- The AWS CLI
- The SAM CLI
- An IaC tool like Terraform or CloudFormation
For this tutorial, we will be using endpts to streamline the development and deployment process of our serverless functions.
endpts is a serverless platform that provides a seamless experience to develop your functions locally and deploy them globally with a single command.
The endpts platform provides:
- out-of-the-box support for TypeScript
- a frictionless local-development experience with live-reloading of changes
- the ability to connect your GitHub repository for automatic deployments on every push
- real-time logs from your functions
All while taking care of the bundling, minifying, packaging, deploying, and routing for your serverless functions 🚀
Introduction
We will build a simple API that generates QR codes. The API will have a single endpoint that accepts the contents of the code in the body and returns a QR that we can render in the terminal or browser. We will use the qrcode package to generate the QR.

Setting up our project
First things first, let's go ahead and set up our project. Switch over to your terminal and let's bootstrap our endpts project:
npm create endpts@latest qr-api
This will create a new directory called qr-api
, install the dependencies, configure TypeScript, and set up the local development server to allow you to test your changes locally without having to trigger a deployment each time.
Let's change into the project directory and install the qrcode
package:
cd qr-api
npm install qrcode
npm install --save-dev @types/qrcode
Writing our function
Now that we have our project set up, we can create our route. Go ahead and create a new file called qr.ts
in the routes
directory with the following content:
// routes/qr.ts
import QRCode from 'qrcode'
import type { Route } from '@endpts/types'
export default {
method: 'POST',
path: '/qr',
async handler(req) {
const body = await req.text()
if (!body) return new Response('No text provided', { status: 400 })
return new Response(await QRCode.toString(body))
},
} satisfies Route
This will create a new route that accepts a POST
request to the /qr
path. The handler will accept the request body and generate a QR code from it. If the request body is empty, we will return a 400
response.
The routes/
directory is where all our API routes are defined. This is where
the endpts builder will look for routes to bundle and deploy.
Let's fire up the development server and test our function:
npm run dev
In a seperate terminal make a POST
request to the /qr
endpoint running locally:
curl -X POST -d "Hello World" http://localhost:3000/qr
We should see the following output:

Deploying our function
Now that we've tested out function locally and are sure it works as intended, let's deploy it!
If you haven't yet, create an account on the endpts Dashboard (there are no forms to fill or credit cards required).
Once you've created an account, you will see a screen that looks like this:

You can connect your GitHub account to automatically deploy your functions on every push or alternatively use the manual deployment method to provide the link to a repository that would automatically be deployed.
To save you some time, we've made the complete code for this tutorial available on GitHub: https://github.com/endpts-samples/qr-api
For this tutorial, we'll use the manual deployment method. Select the Manual Deployment option, give the project a name (e.g.: qr-api
), and provide a repository URL that will be cloned and deployed (e.g.: https://github.com/endpts-samples/qr-api
):

Hit the Deploy project button and in just a couple of minutes, the project will be built and deployed to AWS Lambda and you will recieve a unique deployment URL:

You can now test out your function by sending a POST
request to the /qr
endpoint:
curl -X POST -d "Hello World" https://acme-qr-api.endpts.dev/qr