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

xhrify

v0.0.4

Published

xhr Tools for JS

Downloads

6

Readme

xhrify

xhrify is a tool to make HTTP requests, made simple.

  • xhrify returns a Promise so you can code in sync.

Installation

npm:

$ npm install xhrify -s

Or cdn:

<head>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/xhrify.js"></script>
</head>

Usage

You can use xhrify in two different ways:

Instantiation

// -> The basepath inside the constructor is optional, and can be used in case your need to access different APIS from the same host. If you don't want to use it, just leave it blank and pass your full path inside the functions. If you specify the basepath, you only need to pass the remainder of the full path of your API to the function.

    const xhrify = new xhrify("BASE_PATH_URL") 
    xhrify.get("URL").then((response) => {
        console.log(response);
    })
    .catch((err) => {
        console.log(err);
    })

Static

    xhrify.get("URL").then((response) => {
        console.log(response);
    })
    .catch((err) => {
        console.log(err);
    })

Functions

get

    xhrify.get("http://url.com/api/get").then((response) => {
        alert(response)
    })
    .catch((err) => {
        alert('Error!!!')
    })

post

This takes two arguments, the path and the body of the POST request, and optionally a config, containing the Content-type

This returns a string of the response.

    xhrify.post("http://url.com/api/post", {name: "Bob"}, {ContentType: "application/json"}).then((response) => {
        var result = JSON.parse(response) // Response now in JSON format.
    })
    .catch((err) => {
        alert('Error!!!')
    })

put

    xhrify.put("http://url.com/api/put", {name: "Bob"}).then(() => {
        console.log('PUT completed.')
    })
    .catch((err) => {
        alert('Error!!!')
    })

attach

    xhrify.attach("http://url.com/api/attach", {name: "Bob"}).then((response) => {
        console.log('Attach completed.')
    })
    .catch((err) => {
        alert('Error!!!')
    })

delete

    xhrify.delete("http://url.com/api/delete", {name: "Bob"}).then(() => {
        console.log('Delete completed.')
    })
    .catch((err) => {
        alert('Error!!!')
    })