npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-request-promise

v1.0.10

Published

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

Downloads

5

Readme

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/[email protected]/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
    });