Even more docs, adds response utils to module
This commit is contained in:
parent
5dad5bc0b1
commit
fa73b0bdc0
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@bearmetal/router",
|
||||
"description": "A simple router for Deno",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"stable": true,
|
||||
"files": [
|
||||
"mod.ts",
|
||||
@ -10,7 +10,8 @@
|
||||
],
|
||||
"exports": {
|
||||
".": "./mod.ts",
|
||||
"./types": "./types.ts"
|
||||
"./types": "./types.ts",
|
||||
"./util/response": "./util/response.ts"
|
||||
},
|
||||
"exclude": [
|
||||
".vscode/"
|
||||
|
2
mod.ts
2
mod.ts
@ -5,5 +5,3 @@
|
||||
|
||||
export { Router } from "./router.ts";
|
||||
export { FileRouter } from "./file_router.ts";
|
||||
|
||||
export type { Handler, Middleware } from "./types.ts";
|
||||
|
12
types.ts
12
types.ts
@ -3,6 +3,9 @@
|
||||
* BearMetal Router types
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description a context object for a request
|
||||
*/
|
||||
export interface RouterContext {
|
||||
url: URL;
|
||||
params: Record<string, string | undefined>;
|
||||
@ -27,17 +30,26 @@ export type Middleware = (
|
||||
next: () => Promise<Response>,
|
||||
) => Promise<Response>;
|
||||
|
||||
/**
|
||||
* @description a route configuration
|
||||
*/
|
||||
export interface RouteConfig {
|
||||
pattern: URLPattern;
|
||||
handlers: { [method: string]: Handler };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description a middleware configuration
|
||||
*/
|
||||
export interface MiddlewareConfig {
|
||||
pattern: URLPattern;
|
||||
handler: Middleware;
|
||||
path: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description a route configurator
|
||||
*/
|
||||
export interface RouteConfigurator {
|
||||
get(handler: Handler): RouteConfigurator;
|
||||
post(handler: Handler): RouteConfigurator;
|
||||
|
@ -1,4 +1,35 @@
|
||||
export const NotFound = (msg?: string) =>
|
||||
/**
|
||||
* @module
|
||||
* BearMetal Router response utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description a response with a status of 404
|
||||
*/
|
||||
export const NotFound = (msg?: string): Response =>
|
||||
new Response(msg ?? "Not Found", { status: 404 });
|
||||
export const InternalError = (msg?: string) =>
|
||||
/**
|
||||
* @description a response with a status of 500
|
||||
*/
|
||||
export const InternalError = (msg?: string): Response =>
|
||||
new Response(msg ?? "Internal Server Error", { status: 500 });
|
||||
/**
|
||||
* @description a response with a status of 400
|
||||
*/
|
||||
export const BadRequest = (msg?: string): Response =>
|
||||
new Response(msg ?? "Bad Request", { status: 400 });
|
||||
/**
|
||||
* @description a response with a status of 401
|
||||
*/
|
||||
export const Unauthorized = (msg?: string): Response =>
|
||||
new Response(msg ?? "Unauthorized", { status: 401 });
|
||||
/**
|
||||
* @description a response with a status of 403
|
||||
*/
|
||||
export const Forbidden = (msg?: string): Response =>
|
||||
new Response(msg ?? "Forbidden", { status: 403 });
|
||||
/**
|
||||
* @description a response with a status of 200
|
||||
*/
|
||||
export const Ok = (msg?: string): Response =>
|
||||
new Response(msg ?? "OK", { status: 200 });
|
||||
|
Loading…
x
Reference in New Issue
Block a user