Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

http-kit

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-kit

Platform agnostic fetch kit for the Effect package

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
15
-21.05%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

http

FAQs

Package last updated on 13 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts