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

martonfarago/functional-fetch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functional Fetch

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

Example usage

import { pipe } from "fp-ts/es6/function";
import {
  appendSearchParams,
  getFromURL,
  appendHeaders,
} from "functional-fetch";

const getPost = (id: Number) =>
  pipe(
    new URL(`http://test.dev/posts/${id}`),
    getFromURL,
    appendHeaders({
      Accept: "application/json",
      Authorization: "Bearer token",
    }),
    fetch
  );

const getPosts = (page: string, search: string) =>
  pipe(
    new URL("http://test.dev/posts"),
    appendSearchParams(new URLSearchParams({ page, search })),
    getFromURL,
    appendHeaders({
      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

Languages

  • TypeScript 100.0%