Skip to content

Effect<HttpClientResponse, HttpError | NetworkError, never>

Effect<HttpClientResponse, NetworkError | HttpError.With<ApiError>, never>

Effect<Todo, DecodeError | HttpError | NetworkError, never>

Effect<Todo, DecodeError | NetworkError | HttpError.With<ApiError>, never>

Effect<HttpClientResponse, HttpError | NetworkError | TimeoutError, never>

Effect<HttpClientResponse, NetworkError | TimeoutError | HttpError.With<ApiError>, never>

Effect<Todo, DecodeError | HttpError | NetworkError | TimeoutError, never>

Effect<Todo, DecodeError | NetworkError | TimeoutError | HttpError.With<ApiError>, never>

Effect<Todo, DecodeError | HttpError | NetworkError, never>

Switch an option. The signature is the type TypeScript infers for that exact call.

plugins: []
api.get("/todos/:id", { params: { id }, output: Todo })

The call
api.get("/todos/:id", {
params: { id },(the path requires it)
})
The client's plugins
Fetch.make({ plugins: [
] })

Instances

Typed HTTP calls for Effect, without the boilerplate.

Give Effetch a path and a schema, and you get back a fully typed Effect that tells you every way the call can fail.

pnpm add @monarcode/effetch effect

The same request, two signatures.

Both send the same request and decode the same response. With HttpClient, three failures share one tag. With Effetch, each has its own.

With HttpClient alone

const getTodo = (id: number) =>  Effect.gen(function* () {    const client = yield* HttpClient.HttpClient;    const response = yield* client.get(      `https://api.example.com/todos/${encodeURIComponent(id)}`,    );    const ok = yield* HttpClientResponse.filterStatusOk(response);    return yield* HttpIncomingMessage.schemaBodyJson(Todo)(ok);  });

Effect<Todo, HttpClientError | SchemaError, HttpClient>

HttpClientError
No response, a status outside 200–299, or a body that isn't JSON: three failures under one tag.
SchemaError
A JSON body that doesn't match Todo.
HttpClient
Needs an HttpClient layer before it runs.

With Effetch

const getTodo = (id: number) =>  api.get("/todos/:id", {    params: { id },    output: Todo,  });

Effect<Todo, DecodeError | HttpError | NetworkError, never>

DecodeError
A 2xx body that isn't JSON or doesn't match Todo.
HttpError
A status outside 200–299, with its headers and body.
NetworkError
No response: offline, DNS failure, connection refused, CORS.
never
Needs nothing more to run.

The path is a type.

Every :name in a path is a parameter. TypeScript reads them from the string, so params needs exactly those names, and a path without any takes none.

Paths

/users/:userId/posts/:postId: params needs "postId" | "userId".

/users/:userId/posts/:postId

params needs
"postId" | "userId"
Called right
api.get("/users/:userId/posts/:postId", { params: { userId, postId } });
Called wrong
api.get("/users/:userId/posts/:postId", { params: { userId } });

TS2741 Property 'postId' is missing in type '{ userId: number; }' but required in type 'PathParams<"/users/:userId/posts/:postId">'.

Every failure has a name, until you handle it.

Move the slider through one call. At each stop, the signature is the one TypeScript infers, and the errors handled so far close out of it.

const call = api.get("/todos/:id", {  params: { id: 1 },  output: Todo,}); const found = call.pipe(Fetch.optional); const settled = found.pipe(  Effect.catchTags({    NetworkError: () => Effect.succeed(Option.none()),    DecodeError: (error) => Effect.die(error),  }),);

Effect<Todo, DecodeError | HttpError | NetworkError, never>

Its signature names every way it can fail: no response, a status outside 200–299, or a body that doesn't match.

Specifications.

Where it runs, what it's built on, and where to read about the rest.

Runs on
  • Browsers /
  • React Native /
  • Node.js 20+ /
  • Bun /
  • Deno

Built for each of them: no Node.js modules and no new URL(), so it runs on Hermes too. CI tests on Node.js 24.

Built on
Effect v4's HttpClient and Schema.
Status
A release candidate, 0.1.0-rc.5, on the way to 0.1.0. When a release candidate changes the API, the changelog says what to change in your code.
Checked
Every example in the docs and the README is compiled against the package, and so is every signature on this page.
License
MIT

Set the options. Read the type.

pnpm add @monarcode/effetch effect
Get started