Add basic http router
Update api
This commit is contained in:
@@ -1 +0,0 @@
|
||||
console.log("Hello via Bun!");
|
||||
49
api/src/index.ts
Normal file
49
api/src/index.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
HttpApi,
|
||||
HttpApiBuilder,
|
||||
HttpApiEndpoint,
|
||||
HttpApiGroup,
|
||||
} from "@effect/platform";
|
||||
import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
|
||||
import { Console, Context, Effect, Layer, Schema } from "effect";
|
||||
|
||||
const MyApi = HttpApi.make("MyAPI").add(
|
||||
HttpApiGroup.make("Greetings")
|
||||
.add(HttpApiEndpoint.get("hello-world")`/`.addSuccess(Schema.String))
|
||||
.add(HttpApiEndpoint.get("hello-failure")`/fail`.addError(Schema.String)),
|
||||
);
|
||||
|
||||
class UsersRepository extends Context.Tag("UsersRepository")<
|
||||
UsersRepository,
|
||||
{
|
||||
readonly findById: (id: number) => Effect.Effect<string>;
|
||||
}
|
||||
>() {}
|
||||
|
||||
// const repo = UsersRepository.of({ findById: (id) => Effect.succeed(`${id}`) });
|
||||
|
||||
const GreetingsLive = HttpApiBuilder.group(MyApi, "Greetings", (handlers) =>
|
||||
handlers
|
||||
.handle("hello-world", () =>
|
||||
Effect.gen(function* () {
|
||||
const repository = yield* UsersRepository;
|
||||
yield* Console.log("<- Hello World handler invoked");
|
||||
return yield* repository.findById(42);
|
||||
}),
|
||||
)
|
||||
.handle("hello-failure", () => Effect.fail("Hello fail")),
|
||||
);
|
||||
|
||||
const MyApiLive = HttpApiBuilder.api(MyApi).pipe(Layer.provide(GreetingsLive));
|
||||
|
||||
const userRepoLive = Layer.succeed(UsersRepository, {
|
||||
findById: (id) => Effect.succeed(`${id}`),
|
||||
});
|
||||
|
||||
const ServerLive = HttpApiBuilder.serve().pipe(
|
||||
Layer.provide(MyApiLive),
|
||||
Layer.provide(BunHttpServer.layer({ port: 3000 })),
|
||||
Layer.provide(userRepoLive),
|
||||
);
|
||||
|
||||
Layer.launch(ServerLive).pipe(BunRuntime.runMain);
|
||||
0
api/src/services/auth.ts
Normal file
0
api/src/services/auth.ts
Normal file
Reference in New Issue
Block a user