Skip to content

Commit

Permalink
fix getting started docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Apr 3, 2024
1 parent 11f3926 commit f97fa3b
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
# rtx

[![JSR][JSR badge]][JSR] [![JSR score][JSR score badge]][JSR score]
[![GitHub
Actions][GitHub Actions badge]][GitHub Actions]
[![GitHub Actions][GitHub Actions badge]][GitHub Actions]

> [!NOTE]
>
> Built with [**@fartlabs/rt**](https://github.com/FartLabs/rt) and
> [**@fartlabs/jsonx**](https://github.com/FartLabs/jsonx).
Library of [`@fartlabs/jsonx`](https://github.com/FartLabs/jsonx) components for
composing [`@fartlabs/rt`](https://github.com/FartLabs/rt) routers in JSX.

Minimal HTTP router library based on the `URLPattern` API in JSX.

## Usage

```tsx
import { Get } from "@fartlabs/rtx";

const router = <Get pattern="/" handle={() => new Response("Hello, World!")} />;

Deno.serve((request) => router.fetch(request));
```
## Getting started

### Deno

Let's learn how to get started with rtx by creating a simple router in Deno.

1\. [Install Deno](https://docs.deno.com/runtime/manual).

2\. Start a new Deno project.
Expand All @@ -31,10 +20,45 @@ Deno.serve((request) => router.fetch(request));
deno init
```

3\. Add rtx as a project dependency.
3\. Add `@fartlabs/jsonx` and `@fartlabs/rtx` as project dependencies.

```sh
deno add @fartlabs/jsonx @fartlabs/rtx
```

4\. Add the following values to your `deno.json(c)` file.

```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@fartlabs/jsonx"
}
}
```

5\. Add a file ending in `.[j|t]sx` to your project. For example, `main.tsx`.

```tsx
import { Get, Router } from "@fartlabs/rtx";

const router = (
<Router default={() => new Response("Not found", { status: 404 })}>
<Get
pattern="/"
handle={() =>
new Response("Hello, World!")}
/>
</Router>
);

Deno.serve((request) => router.fetch(request));
```

6\. Spin up your HTTP server by running the `.[j|t]sx` file.

```sh
deno add @fartlabs/rtx
deno run --allow-net main.tsx
```

## Contribute
Expand Down

0 comments on commit f97fa3b

Please sign in to comment.