New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fetchttp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetchttp

`fetchttp` is a small http request/response helper based on fetch

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

fetchttp is a small http request/response helper based on fetch

1. Installation

Add fetchttp.js to your page

<script src="fetchttp.js"></script>

2. API

2.1 a minimal http get request would be like this:

fetchttp.get('https://yourdomain.com')
  .end()
  .then(raw => /* now raw is response from `yourdomain.com` */);

fetchttp support bellow methods:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

2.2 Alternatively you can pass data as second argument:

fetchttp.post('https://yourdomain.com', { str: 'ymy' }).end();

2.3 Last arguments would always be fetch configuration which passes directly to native fetch:

fetchttp.patch('https://yourdomain.com/user/813', { str: 'ymy' }, {
  mode: 'cors',
  credentials: 'include'
}).end();

2.4 The reason why call end() method is inspired by mongoose's queryBuilder, which leet you generate your query step by step then do the query:

fetchttp.post('https://yourdomain.com')
  .set('content-type', 'application/json')
  .set('accept', 'application/json')
  .set('x-csrftoken', '25818910680')
  .send(data)
  .end() // till now send the request

2.5 Finally there are senarios in Project your have to write

const commonConfig = Object.freeze({
  headers: { /* ... */ }
  mode: 'cors'
});
const prefix = 'https://yourdomain.com';

fetch('url', Object.assign(customConfig, commonConfig));

now just:

const api = fetchttp.create({
  baseUrl: 'https://yourdomain.com/v1/',
  options: {
    headers: { /* ... */ },
    mode: 'cors'
  }
});

api.get('data').end(); // would send get request to https:\/\/yourdomain.com/data

FAQs

Package last updated on 08 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts