1.0.2 • Published 4 years ago

async-fetch-url v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

async-fetch-url

async/await implementation of fetchUrl function of fetch package.

Install

npm install async-fetch-url

Fetch from url

fetch.fetchUrl(url [, options])

Where

  • url is the url to fetch
  • options is an optional options object

Options param is same as fetch implementation

Possible options params

{
    headers: {
        "X-My-Header": "Custom header",
        "User-Agent": "MyUseragent/1.0"
    },
    cookies: ["name=value", "key=value; path=/; secure"],
    maxRedirects: 100,//use `disableRedirects: true` to disable redirection, default maxRedirects is 10,
    disableGzip: true //default value is false. Gzip and Deflate is on
    
}

Basic implementation

const fetchUrl = require('async-fetch-url').asyncFetchUrl;
( async() => {
    var url = "https://www.thehindu.com/";
    var response = await fetchUrl(url);
    console.log(JSON.stringify(response));

})();

Output format:

{
    'error': Object,//error.message to get error info
    'meta': Object,
    'data': String //html content of the page
}

Meta object details


1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago