Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='BUN_PUBLIC_*'"
},
"dependencies": {
"@effect/platform": "^0.96.1",
"@effect/platform-bun": "^0.89.0",
"@spiko-tech/effect-react-query": "^1.1.0",
"effect": "^3.21.2",
"@effect/platform-bun": "4.0.0-rc.117",
"@spiko-tech/effect-react-query": "^2.0.0",
"effect": "4.0.0-rc.117",
"react": "^19.2.5",
"react-dom": "^19.2.5"
},
Expand Down
6 changes: 2 additions & 4 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ export function App() {
apiClient.pipe(Effect.flatMap((client) => client.api.testMutation({ payload }))),
onSuccess: () => console.log("Fetched successfully"),
onError: Match.valueTags({
HttpApiDecodeError: (e) => console.error("Decode error:", e.message),
ParseError: (e) => console.error("Parse error:", e.message),
RequestError: (e) => console.error("Request error:", e.message),
ResponseError: (e) => console.error("Response error:", e.message),
SchemaError: (e) => console.error("Schema error:", e.message),
HttpClientError: (e) => console.error("Http client error:", e.message),
BadRequest: () => console.error("BadRequest"),
}),
});
Expand Down
11 changes: 6 additions & 5 deletions example/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "@effect/platform";
import { Schema } from "effect";
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";

export const HelloResponse = Schema.Struct({
message: Schema.String,
method: Schema.String,
});

const mutationEndpoint = HttpApiEndpoint.put("testMutation", "/mutation-test")
.setPayload(Schema.Literal("success", "error", "die"))
.addSuccess(HelloResponse)
.addError(HttpApiError.BadRequest);
const mutationEndpoint = HttpApiEndpoint.put("testMutation", "/mutation-test", {
payload: Schema.Literals(["success", "error", "die"]),
success: HelloResponse,
error: HttpApiError.BadRequest,
});

export const ApiGroup = HttpApiGroup.make("api").add(mutationEndpoint).prefix("/api");

Expand Down
18 changes: 6 additions & 12 deletions example/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpApiBuilder, HttpApiError, HttpServer } from "@effect/platform";
import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
import { Effect, Layer, Match } from "effect";
import { HttpRouter } from "effect/unstable/http";
import { HttpApiBuilder, HttpApiError } from "effect/unstable/httpapi";
import { Api } from "./api";

export const ApiGroupLive = HttpApiBuilder.group(Api, "api", (handlers) =>
Expand All @@ -19,17 +20,10 @@ export const ApiGroupLive = HttpApiBuilder.group(Api, "api", (handlers) =>
),
);

const ApiLive = HttpApiBuilder.api(Api).pipe(Layer.provide(ApiGroupLive));
const ApiLive = HttpApiBuilder.layer(Api).pipe(Layer.provide(ApiGroupLive));

const ServerLive = HttpApiBuilder.serve().pipe(
Layer.provide(
HttpApiBuilder.middlewareCors({
allowedOrigins: ["http://localhost:3200"],
}),
),
Layer.provide(ApiLive),
HttpServer.withLogAddress,
Layer.provide(BunHttpServer.layer({ port: 3000 })),
);
const ServerLive = HttpRouter.serve(
Layer.mergeAll(ApiLive, HttpRouter.cors({ allowedOrigins: ["http://localhost:3200"] })),
).pipe(Layer.provide(BunHttpServer.layer({ port: 3000 })));

BunRuntime.runMain(Layer.launch(ServerLive));
5 changes: 3 additions & 2 deletions example/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchHttpClient, HttpApiClient } from "@effect/platform";
import { Api } from "./api.js";
import { Effect } from "effect";
import { FetchHttpClient } from "effect/unstable/http";
import { HttpApiClient } from "effect/unstable/httpapi";
import { Api } from "./api.js";

export const apiClient = HttpApiClient.make(Api, {
baseUrl: "http://localhost:3000",
Expand Down