hhm

http-hash-mocker

create mock data with http hash

Showing:

Popularity

Downloads/wk

6

GitHub Stars

5

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

4

Size (min+gzip)

4.6KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

http-hash-mocker

http-hash-mocker create request handler

import { HttpRequest, HttpResponse } from "node.http"

type RoutePattern : String

type MockerOpts : {
  basedir: String,
  rootdir?: String,
  locator?: String,
  routes?: Array<RoutePattern>,
  autoGenerate?: Boolean,
  template?: String,
}

type Router : (
  req: HttpReqest,
  res: HttpResponse,
  opts: Object,
  cb: Callback<Error, void>
) => void
type Mocker : { router: HttpHashRouter } & Router

http-hash-mocker : (mopts: MockerOpts) => Mocker
const http = require('http');
const path = require('path');
const sendError = require('send-data/error');

const mocker = require('http-hash-mocker')({
  basedir: path.resolve(__dirname, '../')
  // rootdir: '/',
  // locator: 'test/fixtures',
  routes: [
    '/api/photo/:photoid'
  ],
  autoGenerate: true,
  template: `
module.exports = {
  statusCode: 200,
  body: 'hello data template',
};
`,
});

const server = http.createServer(function (req, res) {
  mocker(req, res, {}, function (err) {
    if (err) {
      if (!res.finished) {
        sendError(req, res, { body: err });
      }
    }
  });
});

test/fixtures/api/photo/200.js

module.exports = {
  statusCode: 200,
  body: 'OK',
};

test/fixtures/api/photo/:photoid.js

const sendPlain = require('send-data/plain');

module.exports = function (req, res, opts, cb) {
  sendPlain(req, res, 'Nine Nine Nine', cb);
};

you mock it.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100