Getting Started
Installation
npx apiker your-site-name
- Edit your Apiker project's app.toml
npm run login
To publish your API
npm run publish
Note: If you have any doubts about app.toml, check out the Durable Object documentation.
Usage
src/index.ts
TypeScript
1import { apiker } from "apiker";2import { getUserCounter } from "./controllers/counter";3import objects from "./objects.json";4 5const routes = {6 "/users/:id/counter": getUserCounter7};8 9apiker.init({10 routes,11 objects,12 exports13});
controllers/counter.ts
TypeScript
1import { Handler, res } from "apiker";2 3export const getUserCounter: Handler = async ({ state }) => {4 const initialCount = (await state().get("counter")) ?? 0;5 const counter = initialCount + 1;6 await state().put({ counter });7 return res({ counter });8};
GET /users/test/counter
{"counter":1}
{"counter":2}
...