Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joshamaju/http-kit

Platform agnostic fetch kit for the Effect package
https://github.com/joshamaju/http-kit

Last synced: 29 days ago
JSON representation

Platform agnostic fetch kit for the Effect package

Awesome Lists containing this project

README

        

# Http Kit

## Features

- Supports interceptors
- Uses Native Web Platform APIs
- Type safety, correctly typed responses and errors
- Cross platform i.e Deno, Node etc using adapters

## Getting started

```bash
npm i http-kit @http-kit/client
npm i @effect/io @effect/data
```

```ts
import * as Http from "http-kit";
import * as HttpClient from "@http-kit/client";
import * as FetchAdapter from "http-kit/fetch";

const client = new HttpClient.Builder()
.setBaseUrl("https://reqres.in/api")
.setAdapter(FetchAdapter.adapter)
.build();

const getUser = Effect.gen(function* (_) {
const http = yield* _(HttpClient.HttpClient);

return yield* _(
http.get("/users/2"),
Http.filterStatusOk,
Http.toJson,
Effect.map((_) => _.data),
Effect.flatMap(S.parse(User))
);
}).pipe(
Effect.tap((data) => Effect.sync(() => console.log(data))),
Effect.tapErrorCause((error) => Effect.sync(() => console.error(error)))
);

Effect.runFork(
pipe(
getUser,
Effect.provideLayer(client.makeLayer()),
Logger.withMinimumLogLevel(LoggerLevel.Debug)
)
);
```

## Examples

[link](playground/basic)