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

node-kall

v1.0.83

Published

A small and intuitive wrapper around `fetch` for consuming REST+JSON-APIs. `kall` is compatible with [Deno](https://deno.land) and [Node](nodejs.org).

Downloads

6

Readme

Kall 🦜 Test

A small and intuitive wrapper around fetch for consuming REST+JSON-APIs. kall is compatible with Deno and Node.

It provides functions for each HTTP Method and an easy API to read their response, as well as handy constants for different status codes.

Documentation

If you or your company is benefitting from kall, consider becoming a sponsor. This way I can work on new features and continue to maintain it worry-free.

Installation

  • Deno: just use URL's like in examples
  • Node: yarn add node-kall

Basic usage

                      //"node-kall" if using Node
import { get, OK } from "https://denopkg.com/olaven/[email protected]/mod.ts";

// Basic GET                   
const [status, todo] = await get("https://jsonplaceholder.typicode.com/todos/1");

console.log((status === OK) ?
    `Fetched Todo: ${todo}` :
    `${status} when fetching todo..`
); 
                      //"node-kall" if using Node
import { get, OK } from "https://denopkg.com/olaven/[email protected]/mod.ts";

// Same as previous example, but with types
type Todo = { userId: number, id: number, title: string, completed: boolean }; //define the type the server is expected to return 
const [status, todo] = await get<Todo>("https://jsonplaceholder.typicode.com/todos/1"); // pass as generic 

console.log((status === OK) ?
    `Fetched Todo: ${todo}` :
    `${status} when fetching todo..`
); 

Every function (get, put, patch, del, post) returns the same format: [ status, body, response].

  • status: is the status code.
  • body: is the JSON-object the API returns (if any)
  • response: is the response fetch would have returned, for when you need it

Similarly, the last argument of any function (2nd for get and del, and 3rd for put, patch and post) takes a RequestInit-object, for when you need to pass custom headers etc.

In addition, kall provides utility functions for extracting only one of these, e.g.: | Name | Example | | ---------------- | ---------------------------------------------------------------- | | filterStatus | const status = await filterStatus(post('/api/todos', newTodo)) | | filterBody | const body = await filterBody(put('/api/todos', updatedTodo)) | | filterResponse | const response = await filterResponse(get('/api/todos')) |

Motivation

The fetch-API is quite straight forward. However, its semantics are confusing.

"fetch"

  1. to go and bring back; return with; get: to go up a hill to fetch a pail of water.
  2. to cause to come; bring: to fetch a doctor. source

In a REST-context, this makes sense for GET-methods, but it breaks down once you use methods like POST and PATCH. This causes friction that should usually be avoided. Furthermore, fetch exposes a lot of data that is not needed. Most of the time, the status code and JSON-body of the response is what's relevant. kall makes the most relevant data available quicky through a very simple API, at the expense of being highly coupled with REST. This makes code easier to read and reason through.

However, "most of the time" is not always. kall makes it possible to get the same information as fetch would in these situations. The difference is that "most of the time" is prioritized.

Make what you want of this :-) It's just a personal experiment that I want to use and share.