Skip to content
Workery

Create App

Create a new Workery app using NPM, Yarn, or PNPM.

sh
npm create cloudflare@latest -- --template iann838/workery/templates/hello-world
sh
yarn create cloudflare@latest --template iann838/workery/templates/hello-world
sh
yarn create cloudflare --template iann838/workery/templates/hello-world
sh
pnpm create cloudflare@latest --template iann838/workery/templates/hello-world

Now, you app is set up, cd into the new folder.

Run Server

Run local development server:

sh
npm run dev
sh
yarn dev
sh
pnpm dev

Check Output

Open your browser at http://127.0.0.1:8787.

You will see the JSON response as:

json
{"message":"Hello World"}

Add Routes

Let's add a new route:

ts
import { Path, Query } from "workery/parameters"
import z from "zod"

app.get("/items/{itemId}", {
    parameters: {
        itemId: Path(z.number().int().min(0)),
        q: Query(z.string().optional()),
    },
    handle: ({ itemId, q }) => {
        return { itemId, q }
    },
})

Interactive Docs

Now go to http://127.0.0.1:8787/docs.

You will see the interactive API documentation (provided by Swagger UI), try it out:

Swagger UI Docs

Alternative Docs

And now, go to http://127.0.0.1:8787/redoc.

You will see the static API documentation (provided by ReDoc):

ReDoc Docs

Deploy App

Deploy your app to Cloudflare Workers:

sh
npm run deploy
sh
yarn deploy
sh
pnpm deploy

OpenAPI Spec

Workery generates a "schema" with all your API using the OpenAPI standard for defining APIs.

A "schema" is a definition or description of something. Not the code that implements it, but just an abstract description. This schema definition includes your API paths, the possible parameters they take, etc.

The term "schema" might also refer to the shape of some data, like a JSON content. In that case, it would mean the JSON attributes, and data types they have, etc.

If you are curious about how the raw OpenAPI schema looks like, Workery automatically generates a JSON (schema) with the descriptions of all your API.

You can see directly at: http://127.0.0.1:8787/openapi.json.

License

This project is licensed under the terms of the MIT license.