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

quip

v0.2.0

Published

A chainable API for response objects in node

Downloads

2,662

Readme

quip

A convenient chainable API for HTTP ServerResponse objects in node.

  • Suited to quick and easy prototyping
  • Works as a Connect middleware
  • Allows you to pipe streams to the response, while easily setting up the headers and status code beforehand

Examples

responding with different status codes

res.ok('<h1>Hello World!</h1>');
res.notFound('Not found');

responding with different mime types

res.text('plain text');
res.json({'stringify': 'this object'});

chaining the two together (in any order)

res.error().json({error: 'something broke'});
res.xml().badRequest('<test></test>');

redirection

res.moved('http://permanent/new/location');
res.redirect('http://temporary/new/location');

custom headers

res.headers({'custom': 'header'}).text('some data');

piping data to a response object

// read posts.xml and pipe to response with mime type application/atom+xml
var feed = fs.createReadStream('posts.xml');
feed.pipe(res.atom());

The response is completed when data is passed to a status code or mime-type function, when a redirect is performed, or when a stream is piped to the response.

Usage

Use quip for specific responses:

var quip = require('quip'),
    http = require('http');

http.createServer(function (req, res) {
    quip(res).ok('example');
});

Enable for all response objects by using quip as a Connect middleware:

var connect = require('connect'),
    quip = require('quip'),

var app = connect(
    quip,
    function (req, res, next) {
        res.ok('example');
    }
);

API

  • headers - add custom headers to response, returns updated response object
  • status - set status code of response manually, returns updated response

Status Codes

By default, the response will have the status code 200 (OK), this can be updated using the following methods. Note that by passing some data to these methods, the response will complete. If you don't pass data it will return an updated response object, allowing you to chain calls together. If the data passed is an object then it will be treated as JSON and the mime type of the response will be updated accordingly.

Success

  • res.ok
  • res.created
  • res.accepted
  • res.noContent

Redirection

  • res.moved
  • res.redirect
  • res.found - alias for redirect
  • res.notModified

Client Error

  • res.badRequest
  • res.unauthorized
  • res.forbidden
  • res.notFound
  • res.notAllowed
  • res.conflict
  • res.gone

Server Error

  • res.error

Mime Types

By default, the response will have the mime-type text/html, this can be updated using the following methods. Note that by passing some data to these methods, the response will complete. If you don't pass data it will return an updated response object, allowing you to chain calls together. You can pass an object to the json and jsonp methods and it will be stringified before sending.

  • res.text

  • res.plain

  • res.html

  • res.xhtml

  • res.css

  • res.xml

  • res.atom

  • res.rss

  • res.javascript

  • res.json

  • res.jsonp -- JSONP is a special case that always completes the request, and overrides any previous status code calls. There is no reliable way for a browser to interpret JSONP responses with a status code other than 200. Any error or status information should be included in the JSONP response itself. The jsonp method accepts 2 arguments, a callback name (string) and some JSON data (either a string or an object literal).