11// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22// This module is browser compatible.
33
4- import type { Chainable , ChainableHandler , OptionalHandler } from "./types.ts" ;
4+ import type {
5+ Chainable ,
6+ ChainableHandler ,
7+ OptionalHandler ,
8+ Responsive ,
9+ } from "./types.ts" ;
510
611/** Immutable chain builder for HTTP handlers.
712 *
@@ -38,7 +43,7 @@ import type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";
3843 * assertEquals(response.headers.get("server"), "deno")
3944 * ```
4045 */
41- export class Chain implements Chainable {
46+ export class Chain implements Chainable , Responsive {
4247 #handlers: readonly ChainableHandler [ ] = [ ] ;
4348
4449 /**
@@ -48,16 +53,24 @@ export class Chain implements Chainable {
4853 this . #handlers = init ?? [ ] ;
4954 }
5055
51- /**
52- * @param handlers
56+ /** Register chainable HTTP handlers.
57+ * @param handlers HTTP chainable handlers.
58+ *
59+ * @example
60+ * ```ts
61+ * import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
62+ *
63+ * const chain = new Chain().next((request, next) => next(), () => new Response("hello"))
64+ * ```
5365 */
5466 readonly next = ( ...handlers : readonly ChainableHandler [ ] ) : this => {
5567 this . #handlers = this . #handlers. concat ( handlers ) ;
5668
5769 return this ;
5870 } ;
5971
60- /**
72+ /** All registered handlers.
73+ *
6174 * @example
6275 * ```ts
6376 * import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
@@ -73,6 +86,16 @@ export class Chain implements Chainable {
7386 /**
7487 * @param request `Request` object. The `Request` is cloned and not mutate.
7588 * @param defaultResponse The default `Response` object. Change the response when the {@link handlers} is empty.
89+ *
90+ * @example
91+ * ```ts
92+ * import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
93+ * import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
94+ *
95+ * const chain = new Chain()
96+ * const response = await chain.respond(new Request("http://localhost"))
97+ * assertEquals(response.status, 404)
98+ * ```
7699 */
77100 readonly respond = (
78101 request : Request ,
0 commit comments