stubr
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

Version License

What is Stubr?

Stubr is a flexibile mock server to stub third party APIs. It can answer API requests based on configured scenarios. Stubr is especially helpful during the development and testing of client applications, that rely on API integrations with services that may...

  • be under development themselves
  • don't expose the test data you need
  • are hard to be put into states that are required to implement and test certain frontend states (e.g. loading behaviour and response to edge cases like service outage)

Stubr allows for incoming request can be...

  • resolved automatically based on scenario validation functions
  • resolved manually via request interceptions
  • observed via Stubr's monitoring UI

Installation

$ npm install stubr

or

$ yarn add stubr

Getting started

Typescript example

Stubr is written in Typescript and thus has built in Typescript support for its usage, too.

import Stubr from 'stubr';
import { Method } from 'stubr';

// instantiate Stubr
const stubr = new Stubr();

// register first scenario
stubr.register({
    name: 'Scenario 1',
    route: '/my/first/route',
    method: Method.GET,
    validate: (
        requestHeaders: object,
        requestBody: object,
        requestParams: object
    ) => {
        return true;
    },
    responseCode: 200,
    responseBody: {
        data: 'my first response',
    },
});

// start Stubr
stubr.run();

Javascript example

const Stubr = require('stubr').default;
const { Method } = require('stubr');

// instantiate Stubr
const stubr = new Stubr();

// register first scenario
stubr.register({
    name: 'Scenario 1',
    route: '/my/first/route',
    method: Method.GET,
    validate: (requestHeaders, requestBody, requestParams) => {
        return true;
    },
    responseCode: 200,
    responseBody: {
        data: 'my first response',
    },
});

// start Stubr
stubr.run();

How to move on?

Please follow our documentation for full reference and more examples.

License

Stubr is licensed under the MIT license.

Package Sidebar

Install

npm i stubr

Weekly Downloads

4

Version

0.5.1

License

MIT

Unpacked Size

3.58 MB

Total Files

22

Last publish

Collaborators

  • chr11