Create an API on the edge using TypeScript and Cloudflare Workers

Ernesto F
Level Up Coding
Published in
10 min readFeb 9, 2020

--

Photo by Daria Shevtsova from Pexels

In my previous post, we described how to use Cloudflare Workers to deploy a static generated website directly to the edge. We also described a way to do faster deploys and rollbacks using a commit hash to decide what version of our Application we will be serving to users.

In this post, we will continue working on top of that to add another piece of our Application’s puzzle, an API. We are going to build it on Cloudflare Workers on the edge and using Workers KV as a data store.

From the last post, we got a handle on the Cloudflare Workers CLI tool named wrangler, let’s start there by installing it and configuring it.

$ npm install -g @cloudflare/wrangler
$ wrangler config

Bootstrapping a TypeScript Project.

Since we are going to use TypeScript we need to set up a build pipeline. I personally prefer to use Rollup (https://rollupjs.org/guide/en/) and from another post we already have a template repo.

--

--