Routes
As seen in the Getting Started page, routes are functions which return the output of "res" helpers.
src/index.ts
TypeScript
1import { res, res_400 } from "apiker";2 3export const myRouteHandler = async ({4 request,5 body,6 headers,7 matches,8 state9}) => {10 // If we want to allow POST only, we explicitly check for it :11 if(request.method !== "POST"){12 // returns 400 Bad Request error.13 // You can also use `res("Invalid Method", 405)`14 return res_400();15 }16 17 // We'll return the request body passed,18 // for example POST form parameters19 // `res` and `res_000` yield JSON. For text output, use `resRaw`20 return res({ body });21};
Parameters
request
https://developers.cloudflare.com/workers/runtime-apis/request/
body
The body of your request, such as form params or plaintext, depending on request content-type
headers
Request headers. Response headers are located at `apiker.responseHeaders`
matches
Your query params and route parts
state
The state method used to interact with permanent storage (check the examples below & docs for more info)