Skip to content
Open
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
12 changes: 7 additions & 5 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FetchHttpClient, HttpApiClient } from "@effect/platform";
import { HttpApiClient } from "@effect/platform";
import { layer as NodeHttpClientLayer } from "@effect/platform-node/NodeHttpClient";
import { CatsApi } from "@effect-cats/domain";
import { Config, Effect } from "effect";

Expand All @@ -14,8 +15,9 @@ const program = Effect.gen(function* () {
const client = yield* HttpApiClient.make(CatsApi, {
baseUrl,
});
// Call the `getUser` endpoint
const result = yield* Effect.either(client.cats.getAllCats());

// Call the `getCats` endpoint (query parameters removed from API)
const result = yield* Effect.either(client.cats.getCats());

if (result._tag === "Left") {
// Handle error
Expand All @@ -26,5 +28,5 @@ const program = Effect.gen(function* () {
}
});

// Provide a Fetch-based HTTP client and run the program
Effect.runFork(program.pipe(Effect.provide(FetchHttpClient.layer)));
// Provide a Node-based HTTP client and run the program
Effect.runFork(program.pipe(Effect.provide(NodeHttpClientLayer)));
21 changes: 16 additions & 5 deletions packages/domain/src/CatsApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import { HttpApi, HttpApiEndpoint, HttpApiGroup } from "@effect/platform";
import { Schema } from "effect";
import { Cat, CatIdFromString } from "./Cats.ts"; // Import Cat and CatIdFromString

// CatId and Cat class are now imported from ./cats.ts
import { Cat, CatIdFromString } from "./Cats.ts";

export class CatNotFound extends Schema.TaggedError<CatNotFound>()(
"CatNotFound",
{
id: Schema.Number, // Refers to the ID by which cat was not found
id: Schema.Number,
},
) {}

// Intended schema for query parameters - kept for future reference
// export const CatsQuerySchema = Schema.Struct({
// breed: Schema.optional(Schema.String),
// age: Schema.optional(Schema.Number),
// name: Schema.optional(Schema.String),
// });

export class CatsApiGroup extends HttpApiGroup.make("cats")
.add(HttpApiEndpoint.get("getAllCats", "/cats").addSuccess(Schema.Array(Cat)))
.add(
HttpApiEndpoint.get("getCats", "/cats")
.addSuccess(Schema.Array(Cat))
// Query parameter definition (.setQuery, .setRequestQuery, or .pipe(HttpApiEndpoint.setOptions(...)))
// was removed due to persistent TypeScript errors indicating the API method was not found or used incorrectly.
// The intended schema (CatsQuerySchema) is defined above for reference.
)
.add(
HttpApiEndpoint.get("getCatById", "/cats/:id")
.addSuccess(Cat)
Expand Down
Loading