Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
/ http-kit Public archive

Platform agnostic fetch kit for the Effect package

License

Notifications You must be signed in to change notification settings

joshamaju/http-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

npm i http-kit @http-kit/client
npm i @effect/io @effect/data
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

About

Platform agnostic fetch kit for the Effect package

Resources

License

Stars

Watchers

Forks

Packages

No packages published