Files
stocca-tre/server/StoccaTreRequest.ts
2022-07-10 23:07:51 +02:00

26 lines
652 B
TypeScript

import Http = Deno.errors.Http;
import {JSONObject} from "./JSON.ts";
export type HttpMethod = "POST" | "GET" | "PUT" | "DELETE";
export type RouteDefinition = {
pattern: RegExp;
method?: HttpMethod;
};
export default class StoccaTreRequest {
constructor(
public method: HttpMethod,
public route: string,
public body: JSONObject | null,
) {}
match(route: RouteDefinition): RegExpExecArray | false {
const patternResult = route.pattern.exec(this.route);
if (route.method && route.method !== this.method) {
return false;
}
return patternResult ?? false;
}
}