0.2.1 • Published 6 years ago

fetch-nodejs v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

fetch-nodejs

Implementation of Fetch API.

API implemented according to recomendations on MDN Fetch API.

Installation

Install Fetch as an npm module and save it to your package.json file as a dependency:

npm install --save fetch-nodejs

Usage

Library provides fetch() method. It accepts string url as necessary parameter and optional object with properties param: Params and headers: Headers. Params and Headers types extend Map, therefore to set params or headers of request use set() method with the name and value arguments.

fetch() method returns promise that resolves to Response type object. Use res.json() to get json result.

Example

    const { fetch, Params } = require('fetch-nodejs');

    const params = new Params()
        .set('page_index', 12)
        .set('page_size', 10)

    fetch('http://test-api.tech/rest/users', { params: params })
    .then(res => res.json())
    .then(
        res => console.log(res), 
        err => console.log('Error', err)
    )
0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago