-
Notifications
You must be signed in to change notification settings - Fork 0
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Example
// ./routes/profile/[name].get.ts
import { route } from "https://serva.land/serva@latest/mod.ts";
export default route(({ hook, param }, meta) => {
console.log(meta);
// => { path: "/profile/[name]", method: "GET", paramNames: ["name"] }
// add hooks
hook(async (request, next) => {
await next();
});
// validate/transform parameters
param("name", (name) => {
return name.charAt(0).toUpperCase() + name.substring(1);
});
return ({ params }) => `Welcome ${params.get("name")}.`;
});API
hook: add hooks to the routeparam: validate/transform a parameter value
interface RouteFactoryApi {
hook: (request: ServaRequest, next: () => Promise<any> | any) => Promise<any> | any;
param: (value: string, request: ServaRequest) => Promise<any> | any;
}Meta
path: the route path (NOT the request path)method: the route method (NOT the request method)paramNames: the route parameter names
interface RouteFactoryMeta {
method: string;
path: string;
paramNames: string[];
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request