0.5.0 • Published 6 months ago

http-kit v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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

0.5.0

6 months ago

0.3.0

8 months ago

0.4.0

8 months ago

0.3.1

8 months ago

0.2.2

9 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.1.0-beta

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago