forked from sukovanej/effect-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
description.ts
40 lines (36 loc) · 1.05 KB
/
description.ts
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
36
37
38
39
40
import { NodeRuntime } from "@effect/platform-node"
import { Schema } from "@effect/schema"
import { Effect, pipe } from "effect"
import { Api, RouterBuilder } from "effect-http"
import { NodeServer } from "effect-http-node"
import { debugLogger } from "./_utils.js"
const Response = pipe(
Schema.Struct({
name: Schema.String,
id: pipe(Schema.Number, Schema.int(), Schema.positive())
}),
Schema.annotations({ description: "User" })
)
const Query = Schema.Struct({
id: pipe(Schema.NumberFromString, Schema.annotations({ description: "User id" }))
})
const api = pipe(
Api.make({ title: "Users API" }),
Api.addEndpoint(
Api.get("getUser", "/user", { description: "Returns a User by id" }).pipe(
Api.setResponseBody(Response),
Api.setRequestQuery(Query)
)
)
)
const app = pipe(
RouterBuilder.make(api),
RouterBuilder.handle("getUser", ({ query }) => Effect.succeed({ name: "mike", id: query.id })),
RouterBuilder.build
)
pipe(
app,
NodeServer.listen({ port: 3000 }),
Effect.provide(debugLogger),
NodeRuntime.runMain
)