Back to packages list

Vals using fets

Description from the NPM package:
TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience
1
2
3
4
5
6
7
8
9
10
11
import { type router } from "https://esm.town/v/maxm/fetsServerExample";
import { createClient } from "npm:fets";
const client = createClient<typeof router>({
endpoint: "https://maxm-fetsserverexample.web.val.run",
});
// The `response` and `greetings` have proper types automatically inferred
const response = await client["/"].get();
const greetings = await response.json();
console.log(greetings);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { createRouter, Response } from "npm:fets";
export const router = createRouter().route({
method: "GET",
path: "/",
schemas: {
responses: {
200: {
type: "object",
properties: {
message: {
type: "string",
},
},
required: ["message"],
additionalProperties: false,
},
},
},
handler: () => Response.json({ message: "Hello from fets!" }),
});
export default router.fetch;

Fets Example

A openapi JSON spec is available at https://pomdtr-fets.web.val.run/openapi.json.

You can access a fully typed client with a single import:

import { client } from "https://esm.town/v/pomdtr/fets";

const resp = await client["/greetings"].get();
const res = await resp.json();

console.log(res.message);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { createClient, createRouter, Response } from "npm:fets@0.7.1";
export const router = createRouter({
swaggerUI: {
endpoint: "/",
},
}).route({
method: "GET",
path: "/greetings",
schemas: {
responses: {
200: {
type: "object",
properties: {
message: {
type: "string",
},
},
required: ["message"],
additionalProperties: false,
},
},
},
handler: () => Response.json({ message: "Hello World!" }),
});
const val = extractValInfo(import.meta.url);
export const client = createClient<typeof router>({
fetchFn: router.fetch,
endpoint: `https://${val.author}-${val.name}.web.val.run`,
});
export default router.fetch;
1
Next