Skip to content

Helpers to use the Fetch API in a more immutable and functional way.

License

Notifications You must be signed in to change notification settings

interferenc/functional-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functional Fetch

Helpers to use the Fetch API in a more immutable and functional way.

Example usage

import {
  appendAllSearchParams,
  getRequest,
  appendAllHeaders,
} from "functional-fetch";
import { pipe, flow } from "fp-ts/es6/function";

const getList = (page: string, search: string) =>
  pipe(
    new URL("http://test.dev"),
    appendAllSearchParams(new URLSearchParams({ page, search })),
    getRequest,
    appendAllHeaders(
      new Headers({ Accept: "application/json", Authorization: "Bearer token" })
    ),
    fetch
  );

const getSingle = flow(
  (id: Number) => new URL(`http://test.dev/post/${id}`),
  getRequest,
  appendAllHeaders(
    new Headers({ Accept: "application/json", Authorization: "Bearer token" })
  ),
  fetch
);

About

Helpers to use the Fetch API in a more immutable and functional way.

Resources

License

Stars

Watchers

Forks

Packages

No packages published