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

@webbspark/web-request

v5.2.5

Published

Fetch wrapper for making HTTP(s) requests easier

Downloads

241

Readme

@webbspark/web-request

Description

Fetch wrapper for making HTTP(s) requests easier

Notes

  • Package uses JSDOC commenting to assist via Intellisense - optimized for VSCode

Importing Package

import { WebbRequest } from '@webbspark/web-request/index.js';

  • Note: for web use - Sever must be able to serve the node_modules/@webbspark folder or it should be copied into a folder the server can serve.
  • Electron apps can access the node_modules folder directly, copying is not necessary

Properties

  • post
  • get
  • put
  • patch
  • delete
  • beforeRun

Request Options

{
    headers?: {[key: string]: any},
    params?: {[key: string]: any},
    mode?: ('cors' | 'no-cors' | 'same-origin'),
    credentials?: ('omit' | 'same-origin' | 'include'),
    cache?: ('default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached'),
    redirect?: ('follow' | 'error' | 'manual'),
    referrerPolicy?: ('no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'),
    integrity?: string,
    keepalive?: boolean,
    signal?: AbortController,
    returnType?: ('arrayBuffer' | 'blob' | 'formData' | 'json' | 'redirect' | 'text'),
    body?: (Blob | ArrayBuffer | DataView | FormData | URLSearchParams | ReadableStream | {[key: string]: any}),
    rawBody?: boolean,
    form?: {[key: string]: any},
}

Response Object

{
    response: ('arrayBuffer' | 'blob' | 'formData' | 'json' | 'redirect' | 'text');
    request: (Request Options && { url?: string, method?: Methods, body?: any});
    statusCode: number;
    statusMessage: string;
}

Use Example

import { WebbRequest } from '@webbspark/web-request/index.js';
const wreq = new WebRequest((opts) => {
    opts.url = `https://someurl.com/${opts.url}`;

    if (!opts.headers) opts.headers = {};
    opts.headers['Accept'] = '*/*';
    opts.headers['User-Agent'] = 'My Application (https://www.my-url.com)';
    opts.headers['Content-Type'] = 'application/json'; 

    opts.headers['Authorization'] = `Bearer ${opts.authToken}`;
    delete opts.authToken; //make sure to delete user defined items, in the options object, before leaving this function
});

const saveNote = (noteText) => {
    return new Promise(async (res, rej) => {
        try {
            const rtn = await wreq.post('http://someurl.com/api/notes', {
                authToken: '<token>',
                body: { note: noteText }
            });
 
            (rtn.statusCode === 200 ? res : rej)(rtn.response);
        } catch (ex) {
            console.log(err);
        }
    });
}

 

Feature Requests and Bug Reporting - NOT IMPLEMENTED

Bug Reporting
Feature Requests

 

License

Copyright (C) 2019 Christopher J. Webb - WebbSpark.com

Permission to use, and/or distribute this software for any legal purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

BY USING THIS SOFTWARE YOU AGREE TO ALL THE TERMS AND CONDITIONS HEREIN.

THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDER/AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

COPYRIGHT HOLDER/AUTHOR RESERVES THE RIGHT TO CHANGE THESE TERMS AND CONDITIONS AT ANY TIME, FOR ANY REASON, WITHOUT PRIOR NOTICE.