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

callo

v0.0.3

Published

Experiment with Minimal Stateful HTTP API

Downloads

2

Readme

Callo, Experiment with Phone-Call Styled Minimal-State HTTP API

Notice

Currently, Callo is still at its probably earliest stage of development. Due to its experimental nature, the API might change in the future to something complete different.

ALSO, Callo requires a front-end wrapper for ease of use, callocall, should be soon available on NPM.

Why?

HTTP is a stateless protocol, and we are all thankful of thisand we are all thankful of this fact that simplifies a lot of things.

However, sometimes we might want to maintain some minimal "states". For example, when an API call sends partially valid data and partially nonsense, we might start processing the valid part (which requires some time and CPU cycles), and then suddenly realize that the rest is nonsense. Sometimes, people would just abort and discards everything, simply sending a status 400. However, it might be nice to actually save the previous part that proves to be valid and their processed result in some "state", and notify the client "hey, you submit something invalid!". When the client realized the problem and submit the correct data, the server could directly resume from this "state", instead of starting running from the very beginning.

Callo is an experiment to see if such idea is going to be proved adequately useful in actual projects. It offers a set of API that allows you easily jump out of a chain of handlers, and jump back in when client submit their corrected data, etc. It further supports rewinding/replaying/skipping handlers. Callo allows you to maintain minimal state, and will be encrypted and send to client, such that no server storage is needed for states. Its front-end package, callocall , further allows interation between API server and client more like RPC or Meteor methods.

Callo is influenced by JWT, Express, React, Redux, Meteor.

Basic Documentation

Create an Callo API Server

const callo = require('callo');

// 256-bit key is used to encrypt state
let srv = callo.server({ key: '5974A1197F7CB9F744CEED4F313DA' });
// or you can supply a password that will be converted to 256-bit key
// let srv = callo.server({ password: 'this-is-a-weak-password' });

Add a Series of Handlers

srv.on('login')
    .use((h, props, state) => {
    	// h is handle
    	// props is data passed from client (has to be able to convert to JSON though)
    	// state is where you can retrieve and set state (has to be able to convert to JSON though)
    	console.log('1st handler for login');
    	h.next();
	})
    .use((h, props, state) => {
    	console.log('2nd handler for login');
    	h.end({ message: 'login successful!' })
	});

Add a Callo Middleware

srv.pre((h, props, state) => {
	state.dataByMiddleware = true;
	h.next(); 
});

Add an Express Middleware

srv.useExpressMiddleware((req, res, next) => {
    console.log('Hi');
    next();
});

Possible Handle Actions

h.end(data) // end handle flow and send data to client

h.next() // go to next handler
h.replay() // rerun the current handler
h.rewind(count) // rewind to a previous handler. h.rewind(0) === h.replay()
h.skip() // skip the next handler
h.jump(count) // jump to a future handler `count` away from current. h.jump(2) === h.skip()

h.order(actionString, data) // request more data from client, would resume from NEXT handler (implicit h.next() while requesting for more data)
h.orderReplay(actionString, data) // order version of h.replay
h.orderRewind(count, actionString, data) // order version of h.rewind
h.orderSkip(actionString, data) // order version of h.skip
h.orderJump(count, actionString, data) // order version of h.jump

Access Raw Request (IncomingMessage) and Response (ServerResponse)

h.req
h.res

Mount API Server for Listening

const http = require('http')

http.createServer(srv.handler()).listen(8000);

Use with Express

const express = require('express');
const app = express();

app.post('/some/path', srv.handler());
app.listen(8000);