New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

instant-request

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instant-request

Client/server agnostic http request library.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

Instant Utils

Client/server agnostic http request library.

Table of Contents

  • Installation
  • Usage
  • API
  • Contributing
  • License

Installation

You can install this package using npm:

$ npm install instant-request

Usage

Here is a quick example to get you started:

ES Modules

import Request from 'instant-request';
const request = new Request('https://example.com');

const test = async () => {
  const response = await request.get('/api/records'); // => https://example.com/api/records
  const json = await response.json();
  console.log(json);
};

CommonJS Modules

var Request = require('instant-request').Request;
var request = new Request('https://example.com');

request
  .get('/api/records') // => https://example.com/api/records
  .then(function(response) {
    response.json().then(function(json) {
      console.log(json);
    });
  });

API

Instantiation

Create an instance of the Request class.

Arguments

baseUrl (String): Base URL for all future requests. options (Object) = {}: Configuration object

Returns

instanceof Request

Example Usage
const request = new Request('https://example.com');

get

Make an HTTP GET request to the specified URI.

Arguments

uri (String): The URI to request, e.g /api/records.
query (Object): The query object to append to the fully qualified URL, e.g { active: 1 } => https://example.com/api/records?active=1.

Returns

Response

Example Usage
async function getCountries() {
  // https://example.com/api/countries
  const response = await request.get('/api/countries');
  const json = await response.json();
  return json;
}

post

Make an HTTP POST request to the specified URI.

Arguments

uri (String): The URI to request, e.g /api/records.
data (Object): The data to POST.
query (Object): The query object to append to the fully qualified URL, e.g { active: 1 } => https://example.com/api/records?active=1.

Returns

Response

Example Usage
async function createCountries() {
  // https://example.com/api/countries
  const response = await request.post('/api/countries', {
    id: 1,
    name: 'Australia',
  });
  const json = await response.json();
  return json;
}

put

Make an HTTP PUT request to the specified URI.

Arguments

uri (String): The URI to request, e.g /api/records.
data (Object): The data to PUT.
query (Object): The query object to append to the fully qualified URL, e.g { active: 1 } => https://example.com/api/records?active=1.

Returns

Response

Example Usage
async function updateCountry() {
  // https://example.com/api/countries
  const response = await request.put('/api/countries/1', {
    animal: 'Kangaroo',
  });
  const json = await response.json();
  return json;
}

delete

Make an HTTP DELETE request to the specified URI.

Arguments

uri (String): The URI to request, e.g /api/records.
query (Object): The query object to append to the fully qualified URL, e.g { active: 1 } => https://example.com/api/records?active=1.

Returns

Response

Example Usage
async function deleteCountry() {
  // https://example.com/api/countries
  const response = await request.delete('/api/countries/1');
  const json = await response.json();
  return json;
}

Contributing

We'd greatly appreciate any contribution you make.

License

MIT

Keywords

FAQs

Package last updated on 17 Dec 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc