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

dame

v1.2.7

Published

minimalistic HTTP client for browser and node

Downloads

591

Readme

dame package size dame package size minzipped dame dependency count Coverage Status

dame minimalistic HTTP client for the browser and Node.js

  • 🚀 Lightweight
  • ⚪️ Zero dependencies.
  • 😀 Easy to use.
  • 🟢 Node (http & https) and 💻 browser (Fetch).
  • 👉 Promise API.
  • ⌛ Custom timeout.
  • 📄 Automatic transforms to JSON data.
  • ⏭ Follows redirects.

📃 Changelog

Table of contents

Import

const dame = require("dame");

Basic examples

GET

const {response} = dame.get("https://rickandmortyapi.com/api/location/1");

POST

const {response} = dame.post("https://your.api.com/login", {
	username: "Username",
	password: "****",
});

Response object

{
	isError: false,
	code: 200,
	status: "OK",
	response: {...},
	error: null,
	redirectCount: 3,
}
  • isError boolean: True if code is >= 200 and < 300 (this is configurable).
  • code number: Status code.
  • status string: Status.
  • response any: Response of the request.
  • error any: If there was any error during the request it will be here.
  • redirectCount number: How many redirects have been followed. Not present if there have been no redirects.

The response can be destructured like this:

const {isError, code, status, response} = dame.get("https://rickandmortyapi.com/api/location/1");

Methods

get, delete

const {response} = dame.get(url, config);
const {response} = dame.delete(url, config);
  • url string: Full URL or path.
    • If you set a baseUrl, this url will be concatenated to it: baseUrl + url.
    • If url starts with "http://" or "https://" the baseUrl from config will be ignored and url will be treated like a full url.
  • config object: See Config.

post, put, patch

const {response} = dame.post(url, body, config);
const {response} = dame.put(url, body, config);
const {response} = dame.patch(url, body, config);
  • url string:See get.
  • body object: The request body.
  • config object: See Config.

Config

  • baseUrl string: Base URL that will be concatenated with the url of the requests.
  • headers object: Headers that will be attached to the request.
  • timeout number: Number of miliseconds that must pass before timeout the request.
  • checkIsError function<boolean>: Function that will receive the status code (number) and must return boolean. Default isError = !(code >= 200 && < 300).
  • Any option that fits on request or fetch.
  • maxRedirects number: Max redirects to follow. Default 20. Use 0 to disable redirects.
  • responseType "arraybuffer" | "stream" | "json" | "text": Browser only. Default "json". Type of the data that the server will respond with.

Configuring base instance

Syntax:

dame.<configKey> = <value>;
  • configKey: any key from Config.
  • value: any value that fits on the config key.

Examples:

dame.baseUrl = "http://localhost:3010";
dame.headers.Authorization = `Bearer abcd.1234`;
dame.timeout = 5000;

Then you'll be able to:

dame.get("/protectedRoute");
// url will be → http://localhost:3010/protectedRoute
// headers will be → {Authorization: "Bearer abcd.1234"}

Creating an instance

const dameInstance = dame.new(config, instanceName?);
  • config object: See Config.
  • instanceName string: (optional) If filled, this instance will be saved on dame.instances.<instanceName>.

Removing a saved instance:

delete dame.instances.<instanceNameToRemove>

Examples

Set base URL

const yourApi = dame.new({
	"baseUrl": "http://localhost:3000",
});

Set headers

const yourApi = dame.new({
	"headers": {
		Authorization: "Bearer abc.123"
	}
});

Editing an instance

yourApi.headers.Authorization: "Bearer new.token";

Special statuses

Timeout

{
	isError: true,
	code: 0,
	status: 'Timed out',
	response: null
}

No response

{
	isError: true,
	code: -1,
	status: "No response from server",
	response: null
}

Offline

{
	isError: true,
	code: -2,
	status: "No internet connection",
	response: null
}

dame vs. others

Package | Browser + Node | Dependencies | Size :---: | :---: | :---: | :---: dame | ✅ | 0 | dame package size phin | ❌ | | phin package size node-fetch | ❌ | | node-fetch package size axios | ✅ | | axios package size got | ❌ | | got package size superagent | ✅ | | superagent package size request | ❌ | | request package size

☝ Return to top