Socket
Socket
Sign inDemoInstall

express-mock-api-middleware

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mock-api-middleware

Express middleware for mocking restful APIs


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

express-mock-api-middleware

Express middleware for mocking restful APIs

Install

npm install --save-dev express-mock-api-middleware

Usage

Express

In your server.js, add the following code

const path = require('path');
const express = require('express');

const app = express();
const mockApiMiddleware = require('express-mock-api-middleware')(
  path.resolve(__dirname, 'mock')
);
app.use(mockApiMiddleware);

path.resolve(__dirname, 'mock') is the folder where mock API files are.

Mock files

For example in file /mock/user.js, you can have content

export default {
  'GET /api/user/info': {
    id: 101,
    userName: 'wilson',
    email: 'wilson@gmail.com',
    firstName: 'Wilson',
    lastName: 'Tian',
  },
  'POST /api/user/login': (req, res) => {
    const { userName, password } = req.body;
    if (userName === 'wilson' && password === 'pass') {
      res.send({
        success: true,
      });
    } else {
      res.send({
        success: false,
      });
    }
  }
};

Keywords

FAQs

Package last updated on 10 Mar 2019

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