Skip to content

Commit 81b5986

Browse files
authored
Added request method and path route (#13)
2 parents c82e340 + 7f4b806 commit 81b5986

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/routing/EndpointRoute.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Request} from "../Request.js";
2+
import {Response} from "../response/index.js";
3+
import {Route} from "./Route.js";
4+
5+
/**
6+
* Routes requests based on HTTP method and path.
7+
*/
8+
export abstract class EndpointRoute implements Route {
9+
private readonly method: Request.Method;
10+
private readonly path: string;
11+
12+
/**
13+
* @param method The required HTTP method to match.
14+
* @param path The request URL path to match.
15+
*/
16+
protected constructor(method: Request.Method, path: string) {
17+
this.method = method;
18+
this.path = path;
19+
}
20+
21+
public match(req: Request): boolean {
22+
return req.method === this.method && req.url.pathname === this.path;
23+
}
24+
25+
public abstract handle(req: Request): Response | Promise<Response>;
26+
}

0 commit comments

Comments
 (0)