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

sendr

v1.2.1

Published

An isomorphic request library with reusable & declarative queries

Downloads

15

Readme

sendr

An isomorphic request library with reusable & declarative queries

Install

npm i sendr
<script src="https://wzrd.in/standalone/[email protected]"></script>

Import

import sendr from 'sendr'
const sendr = require('sendr')

Request

Requests are immutable - every modifier creates a new request, allowing reusability and templating.

const todo = 'https://jsonplaceholder.typicode.com/todos/:id'

const { status, headers, data } = await sendr(todo)
	.params({ id: 1 })
	.type('json')
	.send()
	.progress((current, total) => {
		console.log(`${((current / total) * 100).toFixed(2)}%`)
	})

console.log(data)

Modifiers

path

Append to the request URL.

function path(...paths: sendr.Path[]): sendr.Request

sendr('/users').path('ken')

params

Add or remove URL parameters. Set the value to null or undefined to remove them.

function params(params: sendr.Params): sendr.Request

sendr('/users/:id').params({ id: 'ken' })

method

Set the request method.

function method(method: sendr.Method): sendr.Request

sendr('/posts').method('post')

query

Add or remove query parameters. Set the value to null or undefined to remove them.

function query(query: sendr.Query): sendr.Request

sendr('/users').query({ order: 'ascending' })

credentials

Include credentials in cross-origin requests.

function credentials(credentials: sendr.Credentials): sendr.Request

sendr('https://example.com/posts').method('post').credentials(true) // true or false

headers

Add or remove headers. Set the value to null or undefined to remove them.

function headers(headers: sendr.RequestHeaders): sendr.Request

sendr('/messages')
	.method('post')
	.headers({ 'content-type': 'application/json' })

body

Set the request body.

function body(body: sendr.Body): sendr.Request

sendr('/messages')
	.method('post')
	.headers({ 'content-type': 'application/json' })
	.body(JSON.stringify({ message: 'Hello from sendr!' }))

type

Set the response type.

function type(type: sendr.ResponseType): sendr.Request

sendr('https://jsonplaceholder.typicode.com/todos/:id')
	.params({ id: 1 })
	.type('json')

Publishers

send

Send the request. Returns a Promise containing the response.

function send<Data>(): sendr.FutureResponse<Data>

const { data } = await sendr('/users/ken.png').send()

progress

Listen for the progress of the request.

function progress(progress: sendr.Progress): sendr.Request
function progress(progress: sendr.Progress): sendr.FutureResponse<Data>

const { data } = await sendr('/users/ken.png')
	.progress((current, total) => {
		// Before send
		console.log(`Progress #1: ${((current / total) * 100).toFixed(2)}%`)
	})
	.send()
	.progress((current, total) => {
		// After send
		console.log(`Progress #2: ${((current / total) * 100).toFixed(2)}%`)
	})

abort

Abort the request. Causes the request to fail with code aborted.

function abort(): void

sendr('/users/ken.png').send().abort()

abort (timeout)

Set a timeout for the request. Set the value to null or undefined to remove the timeout. Causes the request to fail with code aborted after the timeout.

function abort(after: sendr.Timeout): sendr.Request
function abort(after: sendr.Timeout): sendr.FutureResponse<Data>

sendr('/users/ken.png')
	.abort(50) // Timeout of 50ms
	.send()
	.abort(null) // Remove the timeout
	.abort(300) // Set a new timeout of 300ms