1.1.1 • Published 3 years ago

lightfetch-node v1.1.1

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

This project is a Work in Progress and currently in development. The API is subject to change without warning.


Install

npm install lightfetch-node

Usage

Main API

await lightfetch(url, [options]);

which returns a <Response>

Options

  • method: HTTP Request Method
  • headers: HTTP Headers to use in Request
  • body: Data to use in the Request*

* Data that can be used in body includes an Object, a string that's in x-www-form-urlencoded format, or plain text. Lightfetch will figure out what you pass in automagically and set the appropriate headers.

Response

The items in a response include:

  • <Response>.status: The status code of a response
  • <Response>.headers: The headers in a response
  • <Response>.cookies: The cookies in a response (uses an API similar to this internally)
  • <Response>.json: A function to parse the content of a response to JSON
  • <Response>.text: A function to parse the content of a response to text

If the above does not statisfy your needs, you can also use <Response>.response to access the unmodified, raw response NodeJS outputs.

Example

// using CommonJS
const { lightfetch } = require('lightfetch-node');

// using ESM
import { lightfetch } from 'lightfetch-node';

async function fetch(url) {
  const res = await lightfetch(url, {
    method: 'GET',
    headers: {
      'X-Requested-With': 'RayhanADev',
    },
  });
  console.log('Status:', res.status);
  console.log('Response:', res.toJSON());
  console.log('Cookies:', res.cookies);
}

fetch('https://postman-echo.com/get?foo=bar');
1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago