Skip to content

Commit

Permalink
Router reference docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Aug 23, 2024
1 parent 8bd66ca commit cd75f6e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 12 deletions.
48 changes: 45 additions & 3 deletions apps/docs/pages/router/add.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
# add

:::warning
Work in progress
:::
Adds a new route to a router module.

## Usage

```ts twoslash
/// <reference types="node" />
// ---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<P>`

```ts
type Route<P extends object> = {
matcher: MatchFunction<P>;
handler: Handler<P>;
};
```

## Parameters

Type: `string`

URL of route.

Type: `Handler`

```ts
type Handler<P extends object = object> = (
match: MatchResult<P>,
matchedRoute: Route<P>,
) => string;
```
32 changes: 29 additions & 3 deletions apps/docs/pages/router/create-router.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# createRouter

:::warning
Work in progress
:::
Create a new router module.

## Usage

```ts twoslash
/// <reference types="node" />
// ---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.
26 changes: 23 additions & 3 deletions apps/docs/pages/router/overview.mdx
Original file line number Diff line number Diff line change
@@ -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
/// <reference types="node" />
// ---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));
```
4 changes: 1 addition & 3 deletions apps/docs/pages/wallet/overview.mdx
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit cd75f6e

Please sign in to comment.