Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bogus-api

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bogus-api

Mock API server for front-end development

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Bogus API

A wrapper around the great json-server. It allows you to specify multiple REST resources. Pass in a directory of Javascript files to be required, and they become your REST endpoints.

Install

npm install bogus-api

Usage

require('bogus-api').create().start({
    resourceDir: './my-resources',
    resourceUriPrefix: '/api/v1',
});

Each JS file in the my-resources directory could look like:

var users = [];
// Create 10 users
for (var i = 0; i < 10; i++) {
    users.push({ id: i, name: 'user' + i });
}
module.exports = users;

Or it could look like:

module.exports = [
    { "id": 1, "title": "json-server", "author": "typicode" },
    { "id": 2, "title": "test", "author": "ccnokes" }
];

So you get a little more flexibility than with plain json-server.

You can add or override routes using the Express API like so:

bogusAPI = require('bogus-api');
var bogusServer = bogusAPI.create({
    // These routes will get mounted before the resources are, allowing you to "short-circuit" them
    // This is useful for testing how the UI reacts to error states from an API
    priorityRoutes: function(server) {
        // the server arg is an instance of an Express server
        server.get('/someRoute', function(req, res) {
            res.status(500).send({ message: 'Some error.' });
        });
    }
}).start();

Options

OptionDescription
portPort the app runs on. 7001 by default.
host0.0.0.0 by default.
resourceUriPrefixPrefixes all resources with a URI.
resourceDirDirectory containing your resources. Default to sample-resources.
proxyObject containing the host and port of the URL to proxy to. No default.
staticDirPath to static directory to serve.
staticUriURI to serve static directory through.

Keywords

FAQs

Package last updated on 28 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc