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

kot

v0.0.1

Published

Got + Ky => Kot

Downloads

9

Readme

[WIP] Got + Ky => Kot

Build Status codecov

Kot is isomorphic HTTP client based on Ky for the browser and Got for Node.js.

Install

$ npm install kot

Usage

import kot from 'kot';

(async () => {
	console.log(await kot('https://example.com').json());
	//=> `{data: '🐈'}`
})();

API

kot(input, [options])

Returns a Response object with Body methods added for convenience. So you can, for example, call kot.json() directly on the Response without having to await it first. Unlike the Body methods of window.Fetch; these will throw an HTTPError if the response status is not in the range 200...299.

kot.get(input, [options])

kot.post(input, [options])

kot.put(input, [options])

kot.patch(input, [options])

kot.head(input, [options])

kot.delete(input, [options])

Sets options.method to the method name and makes a request.

input

Type: string URL

The URL to fetch. Must be an absolute URL.

options

Type: Object

json

Type: Object

Shortcut for sending JSON. Use this instead of the body option. Accepts a plain object which will be JSON.stringify()'d and the correct header will be set for you.

searchParams

Type: string Object<string, string|number> URLSearchParams Default: ''

Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.

prefixUrl

Type: string URL

When specified, prefixUrl will be prepended to input. The prefix can be any valid URL, either relative or absolute. A trailing slash / is optional, one will be added automatically, if needed, when joining prefixUrl and input. The input argument cannot start with a / when using this option.

Useful when used with kot.extend() to create niche-specific Kot-instances.

import kot from 'kot';

// On https://example.com

(async () => {
	await kot('unicorn', {prefixUrl: '/api'});
	//=> 'https://example.com/api/unicorn'

	await kot('unicorn', {prefixUrl: 'https://cats.com'});
	//=> 'https://cats.com/unicorn'
})();
retry

Type: number Default: 2

Retry failed requests made with one of the below methods that result in a network error or one of the below status codes.

Methods: GET PUT HEAD DELETE OPTIONS TRACE Status codes: 408 413 429 500 502 503 504

It adheres to the Retry-After response header.

timeout

Type: number Default: 10000

Timeout in milliseconds for getting a response.

throwHttpErrors

Type: boolean Default: true

Throw a HTTPError for error responses (non-2xx status codes).

Setting this to false may be useful if you are checking for resource availability and are expecting error responses.

kot.extend(defaultOptions)

Create a new kot instance with some defaults overridden with your own.

import kot from 'kot';

// On https://my-site.com

const api = kot.extend({prefixUrl: 'https://example.com/api'});

(async () => {
	await api.get('/users/123');
	//=> 'https://example.com/api/users/123'

	await api.get('/status', {prefixUrl: ''});
	//=> 'https://my-site.com/status'
})();

defaultOptions

Type: Object

kot.HTTPError

Exposed for instanceof checks. The error has a response property with the Response object.

kot.TimeoutError

The error thrown when the request times out.

Compatibility

Node.js 8 or the latest version of Chrome, Firefox, and Safari.

Related

  • got - Simplified HTTP requests for Node.js
  • ky - Tiny and elegant HTTP client based on the browser Fetch API

Maintainers

License

MIT