GithubHelp home page GithubHelp logo

apiculator's Introduction

apiculator

Mock JSON API tool for Node, using:

Directories specify routes; files specify methods

api
└── get.json

Will respond to any GET request to '/' with the JSON in the file.

Header tags give the client control

api
└── session
    ├── post.json
    └── post+bad.json

Generally, if the client POSTs to '/session' then post.json is the response.

However, if the client POSTs to '/session' with the HTTP header X-APICULATOR-TAGS: bad, then the post+bad.json is the response.

Babelon templates and helpers for terse JSON

api
└── users
    └── get.babelon

> api/user/get.babelon

{
  ok: true,
  users: _.times(5, () => ({
    id: faker.random.number(),
    name: `${faker.name.firstName()} ${faker.name.lastName()}`
  }))
}

Rules for when you need them

api
└── gatekeeper
    └── _rules.babelon

> api/gatekeeper/_rules.babelon

[
  // correct password
  {
    request: {
      body: (body) => (body.password === 'secret')
    },
    response: {
      status: 302,
      redirect: '/users'
    }
  },
  // catches all other requests (wrong password)
  {
    response: {
      json: { ok: false }
    }
  }
]

Raw Express route handlers

api
└── express
    └── get.js

> api/express/get.js

  module.exports = function(req, res) {
    res.send(`express says hello ${req.query.name}`);
  }

apiculator's People

Contributors

foysavas avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.