Create App
Create a new Workery app using NPM, Yarn, or PNPM.
npm create cloudflare@latest -- --template iann838/workery/templates/hello-world
yarn create cloudflare@latest --template iann838/workery/templates/hello-world
yarn create cloudflare --template iann838/workery/templates/hello-world
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:
npm run dev
yarn dev
pnpm dev
Check Output
Open your browser at http://127.0.0.1:8787.
You will see the JSON response as:
{"message":"Hello World"}
Add Routes
Let's add a new route:
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:
Alternative Docs
And now, go to http://127.0.0.1:8787/redoc.
You will see the static API documentation (provided by ReDoc):
Deploy App
Deploy your app to Cloudflare Workers:
npm run deploy
yarn deploy
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.