Skip to content

A library for building V8 Isolate web apps on Cloudflare Workers, Deno, and Node.JS

License

Notifications You must be signed in to change notification settings

sister-software/keywork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

What is Keywork?

Keywork is a batteries-included library for building serverless web apps on Cloudflare Workers, Deno, and Node.JS

import { RequestRouter } from './router/index.js'

const app = new RequestRouter()

app.get('/', () => <h1>Hello from Keywork! ๐Ÿ‘‹</h1>)

export default app

GitHub commit activity GitHub Workflow Status (branch) codecov npm npm (scoped) deno module

Why use Keywork?

V8 Isolates are an emerging technology offered by cloud-computing services, that allow web apps to deploy quickly, and be served from around the world. Compared to more traditional cloud services, V8 Isolates offer faster response times, and even scale at more affordable prices than virtual machines and containers.

However, building a web app with V8 Isolates can come with several drawbacks, and may lock your code into a single platform.

Keywork is an open-source library that makes V8 Isolates easier to use.

Serverless web apps without vendor lock-in

Whether you're creating a new web app, or refactoring an existing code-base, choosing a serverless provider is challenging...

You may not have enough information to make a choice between providers such as Cloudflare Workers and Deno Deploy. You may want to try several providers and compare their pricing models, or even self-host your own V8 Isolates platform.

Keywork allows you to build V8 compatible web apps without vendor lock-in, and supports Cloudflare Workers, Deno Deploy, and Node.JS

Routing

Keywork has everything you need to handle incoming requests in a V8 runtime environment. Application routing remains magic-free, and uses an Express.js inspired API that doesn't stray far from the native design patterns of the Worker platform.

interface GreetParams {
  firstName: string
}

app.get<GreetParams>('/greet/:firstName', ({ params }) => {
  return `Hello there! ${params.firstName}`
})

Keywork is the next step when your routing logic outgrows Cloudflare Pages. And thanks to modular and type-safe API, Keywork provides an opinionated and structured guidence as your codebase expands, without locking you into a specific design-pattern.

Try the Router Module โ€บ

React just works

At long last, Keywork takes rendering React on V8 beyond static site generation, and into full dynamic pages.

Server-side rendering is made as simple as pairing JSX with your type-safe API:

interface User {
  displayName: string
  email: string
}

const usersAPI = new RequestRouter()

usersAPI.get('/', () => {
  const users: User[] = [
    { displayName: 'Coheed', email: 'coheed.k@example.com' },
    { displayName: 'Cambria', email: 'claudio.k@example.com' },
    { displayName: 'Ambellina', email: 'ambellina@example.com' },
    { displayName: 'Sirus', email: 'sirus.amory@example.com' },
  ]

  return users
})
const app = new RequestRouter({
  middleware: [['/api/users', usersAPI]],
})

app.get('/users', async () => {
  const response = await this.fetch('/api/users')
  const users: User[] = await response.json()

  return (
    <ul>
      {users.map((user, i) => (
        <li key={i}>{user.displayName}</li>
      ))}
    </ul>
  )
})

Keywork handles client-side hydration, and fits into your existing architecture without ceremony. And with built-in support for streamed responses, your app is delivered and interactive in seconds.

Try the React Module โ€บ

Isomorphic error handling, made easier.

Whether you're handling errors in your V8 Worker, Node.JS, or even the browser, Keywork includes error utilities that pair nicely with HTTP requests.

import { KeyworkResourceError, Status } from './errors/index.js'

interface LoginPayload {
  email: string
  password: string
}

app.post('/login', async ({ request }) => {
  const payload: LoginPayload = await request.body.json()

  if (!payload.email) {
    return new KeyworkResourceError('Email is required', Status.BadRequest)
  }
})

Try the Error Module โ€บ

Code bundling without the guesswork

Using Keywork means that you'll spend less of your precious time configuring ESBuild, and more on the real task at hand โ€” building great web apps.

And with readymade templates available, you can skip the boilerplate and start coding in seconds.

Try the Bundling Module โ€บ

Tools to manage your growing codebase

Cloudflare Workers are limited to just 1 megabyte after compression, and even a modestly-sized codebase may push against this limit.

Keywork allows your web app to be split into smaller and more manageable Worker deployments

Core utilities for building web apps

If you find yourself writing a lot of "glue-code", Keywork also includes the typical "kitchen drawer" stuff you usually have to implement when building a web app, including...

  • Logging that helps you better trace down errors as your app grows
  • Cache headers, cache responses, and even ETag generation for your own content
  • Session management to aid in authenticating users
  • Tools that let you use Cloudflare KV as a NoSQL database like MongoDB or Firebase
  • Static asset utilities with support for Cloudflare Pages and Worker Sites.

All that and much, much more! View all Keywork modules โ€บ

Keywork Starter Kit

The starter kit lets Keywork can be used to build a web app on Cloudflare Pages with your own routing.

  • ๐ŸŒ React
  • ๐Ÿ—๏ธ ESBuild
  • โšก Cloudflare Pages
  • ๐Ÿ’ช Written in TypeScript

More details about the starter kit โ€บ

Want to help?

Keywork is made possible through the countless contributions of the open-source community. There are many ways in which you can contribute to the project.

See our contributing guide โ€บ

Licensing

Keywork is open-source software and distributed under the AGPL-3.0 license. Under the AGPL, you can alter, duplicate redistribute, and incorporate our source code into your application for free, AS LONG AS you comply with the source code sharing requirements of AGPL.