1.0.0 • Published 10 years ago

digit-fetchy v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Fetchy

Simple HTTP package using the new Fetch API.

All responses default to JSON unless specified otherwise

Installation

GITHUB

git clone https://github.com/vjrngn/fetchy/

NPM

npm install 'digit-fetchy'

Usage

In any file :

var http = require('digit-fetchy');

GET request

Simple GET request with default headers

  http.get('some/url/here.com')
    .then(response => {
      console.log(response);
    })
    .catch(errors => {
      console.log(errors)
    });

GET request with custom headers

  let headers = {
    'Accept': 'application/json',
    'x-custom-header': 'foo'
  };

  http.get('some/url/here.com', headers)
    .then(response => {
      // json response here.
    })
    .catch(errors => {
      // any errors here
    });

POST request

Simple POST request with default headers

  let data = {
    name: 'John',
    password: 'foobar'
  };

  http.post('some/url/here.com', data)
    .then(response => {
      // json response here
    })
    .catch(errors => {
      // any errors here
    });

POST request with custom headers

  let data = {
    name: 'John',
    password: 'foobar'
  };

  let headers = {
    'x-foo': 'bar'
  };

  http.post('some/url/here.com', data, headers)
    .then(response => {
      // json response here
    })
    .catch(errors => {
      // any errors here
    });

PUT request

    let data = {
    name: 'John',
    password: 'foobar'
  };

  let headers = {
    'x-foo': 'bar'
  };

  http.put('some/url/here.com', data, headers)
    .then(response => {
      // json response here
    })
    .catch(errors => {
      // any errors here
    });

Request Options

Request OptionsDescriptionValues
modeThe mode contains the mode of the request (e.g., cors, no-cors, cors-with-forced-preflight, same-origin.) This is used to determine if cross-origin requests lead to valid responses, and which properties of the response are readablesame-origin, no-cors, cors (default)
credentialsIndicates whether the user agent (browser) should send cookies from the other domain in the case of cross-origin requests. This is similar to XHR’s withCredentials flag, but with three available values (instead of two).omit, same-origin, include (default)
cacheIndicates the cache mode of the request.default (default), no-store , reload, no-cache, force-cache
1.0.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago