Socket
Socket
Sign inDemoInstall

http-request-promise

Package Overview
Dependencies
5
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    http-request-promise

Yet another promise-based HTTP request library built on jQuery.


Version published
Maintainers
1
Install size
3.91 MB
Created

Readme

Source

http-request-promise

Yet another promise-based HTTP request library using jQuery

Why another HTTP request library using jQuery

  • If you use simlilar library such axios or popsicle for CORS POST request, you may find the request fails at preflight stage (Google Chrome ver 61.0.3). However, the similar request works fine with jQuery. (e.g. this issue). It's actually not axios or popsicle's fault as jQuery sets Conetent-Type of POST requests to application/x-www-form-urlencoded by default and thus doesn't get preflighted. However, it does prove that it might still be a good choice for client side http requests using jQuery to avoid possible issues.

  • jQuery's Promise interface is not compitiable with ES6 Promises. This library warps jQuery's Promise interface with standard ES6 Promise.

  • Simplify the error handling. In case error happens, the thrown error will comes with the following propertoes:

    • statusCode: status code of the response
    • statusText: stats text of the response
    • responseText: response body

Installing

Using npm:

npm install http-request-promise

Using cdn:

<!--Load babel-polyfill for web browser not support ES6 promise yet-->
<script src="https://unpkg.com/babel-polyfill@6.26.0/dist/polyfill.js"></script>
<!--Load jQuery-->
<script src="https://unpkg.com/jquery/dist/jquery.js"></script>
<script src="https://unpkg.com/http-request-promise/dist/index.bundle.min.js"></script>

Usage

import HttpRequestPromise from "http-request-promise";

/**
 * @param url: request Url
 * @param settings: support same options as jQuery.ajax()'s setting parameter
 */
HttpRequestPromise(url,settings)
    .then(function(responseText){
        return responseText; //--- always return http body as plain text
    });

/**
 * @param url: request Url
 * @param data: plain object. Will be sent as part of request url
 */
HttpRequestPromise.get(url,data)
    .then(function(responseText){
        return responseText; //--- always return http body as plain text
    });

/**
 * @param url: request Url
 * @param data: plain object. Will be sent in JSON format as request body
 * @param params: extra parmaters that will be as part of request url
 */
HttpRequestPromise.post(url,data,params)
    .then(function(responseText){
        return responseText; //--- always return http body as plain text
    });

Keywords

FAQs

Last updated on 04 Nov 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc