All Projects β†’ raphaelpor β†’ fitch.js

raphaelpor / fitch.js

Licence: other
A lightweight Promise based HTTP client, using Fetch API.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fitch.js

Gretchen
Making fetch happen in TypeScript.
Stars: ✭ 301 (+760%)
Mutual labels:  fetch, http-client
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+20034.29%)
Mutual labels:  fetch, http-client
Redux Requests
Declarative AJAX requests and automatic network state management for single-page applications
Stars: ✭ 330 (+842.86%)
Mutual labels:  fetch, http-client
fetchx
Beautiful way to fetch data in React
Stars: ✭ 71 (+102.86%)
Mutual labels:  fetch, http-client
Php Fetch
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP
Stars: ✭ 95 (+171.43%)
Mutual labels:  fetch, http-client
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (+28.57%)
Mutual labels:  fetch, http-client
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+20402.86%)
Mutual labels:  fetch, http-client
http4s-dom
http4s, in a browser near you
Stars: ✭ 13 (-62.86%)
Mutual labels:  fetch, http-client
Fetcher Ts
Type-safe wrapper around Fetch API
Stars: ✭ 87 (+148.57%)
Mutual labels:  fetch, http-client
Cross Fetch
Universal WHATWG Fetch API for Node, Browsers and React Native.
Stars: ✭ 1,063 (+2937.14%)
Mutual labels:  fetch, http-client
fetch-wrap
extend WHATWG fetch wrapping it with middlewares
Stars: ✭ 21 (-40%)
Mutual labels:  fetch, http-client
fennch
Modern fetch-based axios-like HTTP client for the browser and node.js
Stars: ✭ 12 (-65.71%)
Mutual labels:  fetch, http-client
Ky Universal
Use Ky in both Node.js and browsers
Stars: ✭ 421 (+1102.86%)
Mutual labels:  fetch, http-client
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-2.86%)
Mutual labels:  fetch, http-client
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+6428.57%)
Mutual labels:  fetch, http-client
Fetch
Asynchronous HTTP client with promises.
Stars: ✭ 29 (-17.14%)
Mutual labels:  fetch, http-client
waspy
WASP framework for Python
Stars: ✭ 43 (+22.86%)
Mutual labels:  http-client
hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-57.14%)
Mutual labels:  fetch
requests-rs
Rust HTTP client library styled after awesome Python requests
Stars: ✭ 37 (+5.71%)
Mutual labels:  http-client
fetch
A fetch API polyfill for React Native with text streaming support.
Stars: ✭ 27 (-22.86%)
Mutual labels:  fetch

Fitch.js

Fitch.js

A lightweight Promise based HTTP client, using Fetch API.

npm version Build Status Documentation Status license

Gitter

Features

  • Uses Fetch API
  • Works on both old and new browsers and on Node.js
  • Supports the Promise API
  • Transform request and response data
  • Automatic transforms for JSON data

Get started

Install

npm i --save fitch

Use

With ES2015 or TypeScript:

import fitch from 'fitch'

CommonJS:

const fitch = require('fitch')

CDN:

unpkg

<script src="https://unpkg.com/fitch/dist/index.umd.min.js"></script>

jsDelivr

<script src="https://cdn.jsdelivr.net/g/fitch.js"></script>

Make your first request:

fitch.get(apiUrl)
  .then(response => console.log(response))

/* Response:
{
  data: { foo: 'bar' },
  status: 200,
  statusText: 'Ok',
  headers: { Content-Type: application/json },
}
*/

Methods available:

get

fitch.get(apiUrl)
  .then(response => console.log(response))

post

const req = {body: {name: 'Happy cat'}}

fitch.post(apiUrl, req)
  .then(response => console.log(response))

put

const req = {body: {name: 'Happy cat'}}

fitch.put(apiUrl, req)
  .then(response => console.log(response))

patch

const req = {body: {name: 'Happy cat'}}

fitch.patch(apiUrl, req)
  .then(response => console.log(response))

del

fitch.del(apiUrl)
  .then(response => console.log(response))

Use with custom configuration

const config = {
  cache: 'no-store',
  headers: { 'Content-Type': 'application/json' },
  mode: 'no-cors',
  params: { // transform to '?test1=test-1&test2=test-2'
    test1: 'test-1',
    test2: 'test-2',
  },
  raw: true, // return the raw output of fetch()
  redirect: 'follow',
}

fitch.get(apiUrl, config)
  .then(response => console.log(response))

See more about fetch configuration at: Fetch API.

Concurrency

all

Helper function for dealing with concurrent requests.

const reqDogs = fitch.get('/dogs')
const reqCats = fitch.get('/cats')

function doSomething([ responseDogs, responseCats ]) {
  console.log('Dogs\t>>>', responseDogs)
  console.log('Cats\t>>>', responseCats)
}

fitch.all([ reqDogs, reqCats ])
  .then(doSomething)

Default Configuration and Request Interceptor

const fetchWrapper = fitch.init({
  config: { raw: true },
  interceptor: response => response.json(),
})

fetchWrapper.get(baseUrl).then(data =>
  console.log('GET with interceptor\t>>>', data)
)

Browser Support

  • Chrome
  • Firefox
  • Edge
  • Safari 6.1+
  • Internet Explorer 10+

Note: modern browsers such as Chrome, Firefox, and Microsoft Edge contain native implementations of window.fetch, so the polyfill doesn't have any affect on those browsers. See more at window.fetch polyfill.

Contributig

Read the Code of conduct.

First yout need to fork this repository. Then:

yarn # install local dependencies
yarn start # run local server
yarn watch:test # watch files inside src/ and tests/
yarn build # run examples
yarn examples # run examples

Note: Your code must be tested and pass in linter check. You can verify your code with ESLint, using npm run lint.

Logo

Copyright Β© BΓ‘rbara Schoen

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].