Skip to content

agroupp/fetch-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
    )

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published