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

stubbatti

v1.2.0

Published

A command line stub http server with the special DSL.

Downloads

14

Readme

Stubbatti v1.2.0

Build Status Coverage Status Npm Version MIT License

Dependency Status

A command line stub http server with the special DSL.

Install

  • Install node.js ( >= 0.9 ).

  • Using npm, install stubbatti command globally:

npm install -g stubbatti

Usage

Stubbatti is configurable with the file named .stubbatti.js or stubbatti.js.

And in it you can write like following:

get('/hello', 'Hello, world!');

And if you run the command stubbatti then stubbatti server will start listening on port 28987 (by default) and will serve the string Hello, world! when the path /hello requested.

Reference

.stubbatti.js reference

Basic Response

You can set a response body for the path:

get('/hello', 'Hello, world!');

With the above, /hello responses Hello, world! with http status 200.

Response delay

You can delay response with delay option:

get('/slow', 'slow response', {delay: 3000});

With the above, /slow responses after the delay of 3000 miliseconds.

This is useful for testing timeout features of client libraries.

Content-Type

You can specify the content-type of the reponse with contentType option:

get('/json', '{"a":1}', {contentType: 'application/json'});

With the above, /json responses {"a":1} with Content-Type: application/json.

Status Code

You can specify the status code of the response with status option:

get('/402', 'payment required', {status: 402});

With the above, /402 responses payment required with http status code 402.

Custom Headers

You can specify custom headers with headers option:

get('/custom', '{"a":1}', {headers: {
    'X-Custom': 'abc',
    'X-Header': 'def'
}});

With the above settings, /custom responses with the HTTP headers like:

X-Custom: abc
X-Header: def

Other Methods

Available methods are get, post, head, options, put, delete.

Followings are valid notations in .stubbatti.js.

get('/foo', 'GET response');
post('/foo', 'POST response');
head('/foo', ''); // HEAD response cannot have a response body.
options('/foo', 'OPTIONS response');
put('/foo', 'PUT response');
global.delete('/foo', 'DELETE response');
trace('/foo', 'TRACE response');

Setting port

You can set the stub server's port number with port method:

port(80);

The default port number of stubbatti is 28987.

Syntax and semantics

The syntax and semantics of .stubbatti.js is basically same as node.js except some addition of global methods above.

Command Line Options

With --config option, you can specify a custom stubbatti file.

stubbatti --config my_stub_settings.js

With --kill option, you can kill the server. With this option, you can set your test script like following:

stubbatti & # launches a stub server

# run unit test using the stub http server
...

stubbatti --kill # kills the stub server

Special Paths

A HEAD request to the path /__kill has the special meaning, which is used for killing the server process. So you shouldn't write head('__kill', ...); in .stubbatti.js.

LICENSE

MIT

Note

This command is a thin wrapper of express and focusing on stubbing an http server on test environments. This cli should be useful when you write the unit test of an http client or a web api client.

API documentation

Similar tools

  • Betamax for JVM languages
  • VCR for Ruby
  • WireMock for JVM languages
  • Stubby for JVM languages and has CLI
    • Stubby is very similar to stubbatti, but the main target is JVM language with gradle build configuration.
  • wiremock-php for PHP
  • objc-mocktail for Objective-C

The difference of stubbatti from the above tools is that it's just a CLI stub server and can be used with any language through hooks in a shell script. And it needs only one setting file .stubbatti.js with the simple language.

Release History

  • 2014-06-05 v1.1.0 Initial release.