Code Monkey home page Code Monkey logo

stubon's Introduction

Build Status Coverage Status MIT License

Stubon

stubon is simple dummy api server.

0. install

$ npm i -D stubon

1. Make source file by JSON or YAML or both.

When "http request" includes all condition that written under "request", value returned that under correspond "response.body". Sample is here.

// ./dev/src/dummy.yml
'/aaa/get':
    -
        request:
            method: 'GET'
        response:
            status: 200
            body:
                result: 'OK!'

2. Create server.

2.1 The way to make with a file.

var Stubon = require('stubon').default; // = import Stubon from 'stubon';

var srcPath = './dev/src';
var stubon = new Stubon(srcPath, {
    debug : true,
    ssl   : true,
});

stubon.server().listen(8080);

2.2 The way to make with a command line.

$ $(npm bin)/stubon -p 8080 -s ./dev/src --debug --ssl

3. Call a dummy API.

$ open https://localhost:8080/aaa/get

If you call API from node script, you need setting option 'agent'.
When you call from browser, you can do permission setting on the browser side.

// call_api.js
fetch('https://localhost:8080/aaa/get', {
    agent : new https.Agent({ rejectUnauthorized : false }),
})
    .then(function(res) {
        return res.json();
    })
    .then(function(json) {
        console.log(json.result); // OK!
    });
$ node call_api.js

stubon's People

Contributors

dependabot[bot] avatar putan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

shibe97

stubon's Issues

js setting files

I want to be able to use the setting file written in javascript

e.g.

const message = 'hoge';

export default {
    '/hoge' : [
        request: {
            method: 'GET',
        },
        response: {
            status: 200,
            body: {
                result: [
                    { id: 1, msg: message }, // can use variables.
                    { id: 2, msg: message },
                ],
            },
        },
    ],
};

hot reload

I want to monitor the setting file and reflect it immediately when there is a change.

Accept enum

e.g.

'/aaa/get':
    -
        request:
            method: 'GET'
            queries:
                type: '{TYPE_A|TYPE_B}'   <- match 'TYPE_A' or 'TYPE_B'
        response:
            status: 200
            body:
                result: 'OK! aaa!'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.