diff --git a/apps/docs/pages/router/add.mdx b/apps/docs/pages/router/add.mdx index 511082f..ebe8883 100644 --- a/apps/docs/pages/router/add.mdx +++ b/apps/docs/pages/router/add.mdx @@ -1,11 +1,53 @@ # add -:::warning -Work in progress -::: +Adds a new route to a router module. ## Usage +```ts twoslash +/// +// ---cut--- +import { createApp } from "@deroll/app"; +import { createRouter } from "@deroll/router"; + +// create app +const app = createApp({ url: "http://127.0.0.1:5004" }); + +// create router +const router = createRouter({ app }); +router.add<{ name: string }>( // [!code focus] + "hello/:name", // [!code focus] + ({ params: { name } }) => `Hello ${name}`, // [!code focus] +); // [!code focus] + +app.addInspectHandler(router.handler); + +// start app +app.start().catch((e) => process.exit(1)); +``` + ## Returns +Type: `Route

` + +```ts +type Route

= { + matcher: MatchFunction

; + handler: Handler

; +}; +``` + ## Parameters + +Type: `string` + +URL of route. + +Type: `Handler` + +```ts +type Handler

= ( + match: MatchResult

, + matchedRoute: Route

, +) => string; +``` diff --git a/apps/docs/pages/router/create-router.mdx b/apps/docs/pages/router/create-router.mdx index 12bb0c9..a696378 100644 --- a/apps/docs/pages/router/create-router.mdx +++ b/apps/docs/pages/router/create-router.mdx @@ -1,11 +1,37 @@ # createRouter -:::warning -Work in progress -::: +Create a new router module. ## Usage +```ts twoslash +/// +// ---cut--- +import { createApp } from "@deroll/app"; +import { createRouter } from "@deroll/router"; + +// create app +const app = createApp({ url: "http://127.0.0.1:5004" }); + +// create router +const router = createRouter({ app }); // [!code focus] +router.add<{ name: string }>( + "hello/:name", + ({ params: { name } }) => `Hello ${name}`, +); + +app.addInspectHandler(router.handler); + +// start app +app.start().catch((e) => process.exit(1)); +``` + ## Returns +Type: `Router` + ## Parameters + +Type: `App` + +Application instance. diff --git a/apps/docs/pages/router/overview.mdx b/apps/docs/pages/router/overview.mdx index e0a0fdc..087a3c2 100644 --- a/apps/docs/pages/router/overview.mdx +++ b/apps/docs/pages/router/overview.mdx @@ -1,5 +1,25 @@ # Router -:::warning -Work in progress -::: +The `@deroll/router` modules provides a simple routing mechanism that can be used by [inspect handlers](../inspect-handlers) to route requests to different handlers based on a URL mechanism. + +```ts twoslash +/// +// ---cut--- +import { createApp } from "@deroll/app"; +import { createRouter } from "@deroll/router"; + +// create app +const app = createApp({ url: "http://127.0.0.1:5004" }); + +// create router +const router = createRouter({ app }); +router.add<{ name: string }>( + "hello/:name", + ({ params: { name } }) => `Hello ${name}`, +); + +app.addInspectHandler(router.handler); + +// start app +app.start().catch((e) => process.exit(1)); +``` diff --git a/apps/docs/pages/wallet/overview.mdx b/apps/docs/pages/wallet/overview.mdx index 9ec8d38..1e9eb32 100644 --- a/apps/docs/pages/wallet/overview.mdx +++ b/apps/docs/pages/wallet/overview.mdx @@ -1,5 +1,3 @@ # Wallet -:::warning -Work in progress -::: +The `@deroll/wallet` module provides an in-memory wallet management system, and some utility functions to deal with assets.