Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rayhanadev/lightfetch
Zero dependencies, lightweight, and asynchronous https requests package.
https://github.com/rayhanadev/lightfetch
deno https nodejs
Last synced: 3 months ago
JSON representation
Zero dependencies, lightweight, and asynchronous https requests package.
- Host: GitHub
- URL: https://github.com/rayhanadev/lightfetch
- Owner: rayhanadev
- License: mit
- Created: 2021-06-15T21:42:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-24T15:39:07.000Z (over 3 years ago)
- Last Synced: 2024-11-07T11:05:06.192Z (3 months ago)
- Topics: deno, https, nodejs
- Language: JavaScript
- Homepage:
- Size: 1.69 MB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
> This project is a **Work in Progress** and currently in development. The API is
> subject to change without warning.
A small fetching package for super simple usages.
Built using zero dependencies to be lightweight
and asynchronous.
Lightfetch gives you the best of size, speed, and usability.
---
## Install
```sh
npm install lightfetch-node
```## Usage
### Main API
```js
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:
- `.status`: The status code of a response
- `.headers`: The headers in a response
- `.cookies`: The cookies in a response (uses an API similar to [this](https://github.com/nfriedly/set-cookie-parser) internally)
- `.json`: A function to parse the content of a response to JSON
- `.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`
> to access the unmodified, raw response NodeJS outputs.## Example
```js
// 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');
```