Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/joshamaju/http-kit
- Owner: joshamaju
- License: mit
- Created: 2023-07-16T08:20:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-13T21:09:42.000Z (12 months ago)
- Last Synced: 2024-04-14T13:16:31.216Z (7 months ago)
- Language: TypeScript
- Size: 102 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)