Template
1
0

feat: update docs

This commit is contained in:
2025-04-18 21:27:08 +00:00
parent 74ab1644d6
commit 9ae0f377c7
4 changed files with 19 additions and 15 deletions

View File

@@ -39,10 +39,11 @@ After creating our first route we mount it onto our relay instance.
```ts
import { Relay } from "@valkyr/relay";
import { adapter } from "@valkyr/relay/http";
import route from "./path/to/route.ts";
export const relay = new Relay([
export const relay = new Relay({ url: "http://localhost:3000/api", adapter }, [
route
]);
```
@@ -54,10 +55,11 @@ We have now finished defining our initial relay setup which we can now utilize i
To be able to successfully execute our user create route we need to attach a handler in our `api`. Lets start off by defining our handler.
```ts
import { UnprocessableContentError } from "@valkyr/relay";
import { Api, UnprocessableContentError } from "@valkyr/relay";
import { relay } from "~project/relay/mod.ts";
export const api = new Api([
relay
.route("POST", "/users")
.handle(async ({ name, email }) => {
@@ -66,7 +68,8 @@ relay
return new UnprocessableContentError();
}
return user.id;
});
})
]);
```
We now have a `POST` handler for the `/users` path.

View File

@@ -1,7 +1,7 @@
import { RequestInput } from "../libraries/relay.ts";
import { RelayAdapter } from "../mod.ts";
export const http: RelayAdapter = {
export const adapter: RelayAdapter = {
async fetch({ method, url, search, body }: RequestInput) {
const res = await fetch(`${url}${search}`, { method, headers: { "content-type": "application/json" }, body });
const data = await res.text();

View File

@@ -2,7 +2,8 @@
"name": "@valkyr/relay",
"version": "0.1.0",
"exports": {
".": "./mod.ts"
".": "./mod.ts",
"./http": "./adapters/http.ts"
},
"publish": {
"exclude": [

View File

@@ -1,11 +1,11 @@
import z from "zod";
import { http } from "../../adapters/http.ts";
import { adapter } from "../../adapters/http.ts";
import { Relay } from "../../libraries/relay.ts";
import { route } from "../../libraries/route.ts";
import { UserSchema } from "./user.ts";
export const relay = new Relay({ url: "http://localhost:36573", adapter: http }, [
export const relay = new Relay({ url: "http://localhost:36573", adapter }, [
route
.post("/users")
.body(UserSchema.omit({ id: true, createdAt: true }))