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

flare-gun

v0.8.3

Published

REST API endpoint testing library

Downloads

24

Readme

Flare Gun Build Status

A JSON REST API testing framework

Install

$ npm install flare-gun

Example, using mocha

$ npm install mocha Joi

Default config for Joi validation:

{
  convert: false,
  presence: 'required'
}
var Joi = require('joi')
var flareGun = require('flare-gun')
var flare = flareGun.route('http://myapp.com/api')

describe('MyApp', function () {
  it('gets users', function () {
    return flare
      .get('/users')
      .expect(200, Joi.array().includes({
        id: Joi.number(),
        username: Joi.string().required(),
        avatar: Joi.string()
      }))
  })

  it('creates users', function () {
    return flare
      .post('/users', {username: 'joe'})
      .expect(200)
      .stash('joe')
      .get('/users/:joe.id')
      .expect(200, {
        id: Joi.number(),
        username: Joi.string().required(),
        avatar: Joi.string()
      })
  })
})

Usage

.request({String uri, String method}) -> FlarePromise
.get(String uri, Object queryString, Object options) -> FlarePromise
.expect(String statusCode, Object|{Joi} response) -> FlarePromise
.post(String uri, Object body, Object options) -> FlarePromise
.put(String uri, Object body, Object options) -> FlarePromise
.patch(String uri, Object body, Object options) -> FlarePromise
.del(String uri, Object body, Object options) -> FlarePromise
.stash(String name, Function<Stash> -> Object) -> FlarePromise
.thru(Function<FlarePromise>(FlarePromise)) -> FlarePromise
.do(Function<FlarePromise>) -> FlarePromise

Options are passed through to request Stashed variables can be injected in any string, by prefixing with a :
e.g.

flareGun
  .post('/user')
  .stash('joe')
  .post('/users/:joe.id', {name: ':joe.name'})
  .expect(200, {id: ':joe.id'})
  .post('/users/:joe.id', {name: ':joe.name'})
  .expect(200, Joi.object().keys({
    id: ':joi.id'
  }))
  .post('/users/friends', ':joe')
  .expect(200, ':joe.id')
  .get('/users/:joe.id')
  .expect(200, ':joe')
.actor(String name, Object requestObj) -> FlarePromise

requestObj gets combind with requests before being passed to request.js

.as(String name) -> FlarePromise
flareGun
  .actor('joe', {
    auth: {
      user: 'joe',
      pass: 'joePass'
    }
  })
  .actor('anon', {})
  .as('joe')
  .get('/asJoe')
  .as('anon')
  .get('/asAnon')
.route(String url) -> FlarePromise

Set the base url for requests

.express({Express} app) -> FlarePromise

Pass in an express server object to make calls to, instead of a url Also accepts a promise of an express server

.close() -> FlarePromise

Close express server. May close more connections in the future.

.exoid(String path, Object body) -> FlarePromise

Calls an exoid method at '/exoid'. See https://github.com/Zorium/exoid

Contributing

$ npm test

Changelog

  • 0.7.x -> 0.8.x
    • expect(cb) is now passed res.body instead of res
  • 0.6.x -> 0.7.x
    • add graph()
    • upgrade Joi (now peer dependency)
    • add userAgent string default
    • expect(cb) promise support
  • 0.5.x -> 0.6.0
    • Flare gun has become properly pure, which means that side effects will not impact other chains
      This also means that Flare gun has become a singleton, without needing to be instantiated.
    • Removed flare method
    • Added thru method