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

@ticketmaster/yakbak

v2.4.1-tm1

Published

Record and playback HTTP responses

Downloads

2

Readme

yakbak

Record HTTP interactions The Node Way™. Inspired by ruby's vcr.

Build Status

install

$ npm install yakbak --save-dev

usage

The main idea behind testing HTTP clients with yakbak is:

  1. Make your client's target host configurable.
  2. Set up a yakbak server locally to proxy the target host.
  3. Point your client at the yakbak server.

Then develop or run your tests. If a recorded HTTP request is found on disk, it will be played back instead of hitting the target host. If no recorded request is found, the request will be forwarded to the target host and recorded to disk.

yakbak(host, options)

Returns a function of the signature function (req, res) that you can give to an http.Server as its handler.

var handler = yakbak('http://api.flickr.com', {
	dirname: __dirname + '/tapes'
});

options

  • dirname the path where recorded responses will be written (required).

with node's http module

yakbak provides a handler with the same signature that http.Server expects so you can create your own proxy:

var http = require('http');
var yakbak = require('yakbak');

http.createServer(yakbak('http://api.flickr.com', {
	dirname: __dirname + '/tapes'
})).listen(3000);

Now any requests to http://localhost:3000 will be proxied to http://api.flickr.com and recorded to /tapes for future playback.

with express

Need more flexibility? express expects the same function signature, so you can use yakbak just like you would any other middleware:

var express = require('express');
var yakbak = require('yakbak');

var flickr = yakbak('http://api.flickr.com', {
	dirname: __dirname + '/tapes'
});

var upload = yakbak('http://up.flickr.com', {
	dirname: __dirname + '/tapes'
});

express().use(function (req, res, next) {
	if (req.path.indexOf('/services/upload') === 0) {
	  upload(req, res);
	} else {
	  flickr(req, res);
	}
}).listen(3000);

as a standalone response server

Each recorded response is itself a node module with the same handler signature, so if you want to create a server that replays a single response, you can do so easily:

var http = require('http');
var tape = require('./tapes/1117f3d81490d441d826dd2fb26470f9.js');

http.createServer(tape).listen(3000);

on the command line

yakbak also ships with a yakbak utility that will start an HTTP server to play back a given tape.

$ yakbak
Error: file is required
Usage: yakbak <file>
$ yakbak ./tapes/1117f3d81490d441d826dd2fb26470f9.js
Server listening on port 3000
* Connection from 127.0.0.1 port 63669
< GET / HTTP/1.1
< host: localhost:3000
< user-agent: curl/7.43.0
< accept: */*
<
> HTTP/1.1 201 Created
> content-type: text/html
> date: Sat, 26 Oct 1985 08:20:00 GMT
> connection: close
> transfer-encoding: chunked
>
* Connection closed

license

This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.