Skip to content

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

 
 
 

Contributors

Languages

  • TypeScript 100.0%