Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fitch

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fitch

Test using fetch API

  • 0.4.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Fitch.js

Fitch.js

A lightweight Promise based HTTP client, using Fetch API.

Build Status license

Get started

Install

npm i --save fitch

Use

With ES2015 or TypeScript:

import fitch from 'fitch'

CommonJS:

const fitch = require('fitch')

UMD:

<script src="node_modules/fitch/src/index.js"></script>

Make your first request:

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

Methods available:

get

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

post

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

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

put

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

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

patch

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

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

delete

fitch.delete(apiUrl)
  .then(data => console.log(data))

Use with custom configuration

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

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

See more about fetch configuration at: Fetch API.

Browser Support

| IE / Edge | Firefox| Chrome | Safari | | --------- | --------- | --------- | --------- | --------- | --------- | | IE10, IE11, Edge| Every versions| Every versions| 6.1+|

Note: This assumes that you’re using a transpiler like Babel.

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

First yout need to fork this repository. Then:

npm i # install local dependencies
npm start # run local server
npm run watch:test # watch files inside src/ and tests/
npm run 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.

FAQs

Package last updated on 07 Nov 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc