Skip to content
Merged
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
106 changes: 13 additions & 93 deletions example/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"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",
"@spiko-tech/effect-react-query": "^2.0.0",
"@tanstack/react-query": "^5.104.0",
"effect": "4.0.0",
"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(`${e.reason._tag}:`, 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/http-api";

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/http";
import { HttpApiBuilder, HttpApiError } from "effect/http-api";
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/http";
import { HttpApiClient } from "effect/http-api";
import { Api } from "./api.js";

export const apiClient = HttpApiClient.make(Api, {
baseUrl: "http://localhost:3000",
Expand Down
4 changes: 3 additions & 1 deletion example/src/frontend.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import myReactSinglePageApp from "./index.html";

Bun.serve({
const server = Bun.serve({
routes: {
"/": myReactSinglePageApp,
},
port: 3200,
});

console.log(`Server is running on ${server.url}`);
1 change: 0 additions & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
Expand Down
Loading