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

breaking

v0.1.2

Published

helper suit, for create and mock rest api, test api

Downloads

7

Readme

breaking

nodejs helper suit, for create and mock rest api, test api

Installation

Using npm:

npm i --save breaking

Usage

  1. breaking.bad Create REST API server very fast.
  2. breaking.request Verify A REST API server.

breaking.bad

Describe Your APIs

Here's an example: (save as 'discovery.coffee')

module.exports =
    basePath: 'http://127.0.0.1:3010/api'
    apis: [
        {
            name: 'login'
            path: '/users/login'
            httpMethod: 'POST'
            data:
                username: '[email protected]'
                password: 'dev'
            response:
                '?id': 'nq41UtaBL2F79'
                token: 'kHJsOH3GZCOqPnsP0rsT4yqLB5mXH'
                ttl: 999
                created: '20140822 12:05:46'
                uid: 1
            errorResponses: []
        }

        {
            name: 'homepage'
            path: '/homepage'
            httpMethod: 'GET'
            query:
                page: 1
            response: [
                {
                    tid: 1
                    subject: 'Face Me'
                    message: 'I am content.'
                    forum:
                        fid: 2
                        name: 'news'
                        fup: 0
                }
            ]
            errorResponses: []
        }
    ]

Boot the Mock API Server

express = require 'express'
breaking = require 'breaking'
resource = require './discovery'

app = express()

breaking.bad app, resource

app.listen 3400
console.log 'breaking.bad listen to 3400...'

Done!

% coffee app.coffee
breaking.bad listen to 3400...

% curl -X GET http://127.0.0.1:3400/api/homepage
[{"tid":1,"subject":"Face Me","message":"I am content.","forum":{"fid":2,"name":"news","fup":0}}]

% curl -X POST http://127.0.0.1:3400/api/users/login
{"?id":"nq41UtaBL2F79","token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1}%

breaking.request

see: test/login.test.coffee

breaking = require 'breaking'
api = breaking.request require './discovery'

api.login.request (err, token)->
    expect(api.login.verify token).to.be.ok

This code do it:

  1. POST 'http://127.0.0.1:3010/api/user/login'

  2. check the response is patternEqual as descibed by 'discovery.coffee'

patternEqual

when request login api, server return:

  • {"id":"nq41UtaBL2F79","token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : PASS

  • {"token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : PASS (?id set id is optional in response)

  • {"id": 5, "token":"kHJsOH3GZCOqPnsP0rsT4yqLB5mXH","ttl":999,"created":"20140822 12:05:46","uid":1} : FAIL (id shounld be a string, but return a number)