Skip to content

antife-yinyue/http-mock-middleware

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http-mock-middleware

A Http Mock Middleware for Express.js

Install

npm install --save http-mock-middleware

Usage

const mockMiddleware = require('http-mock-middleware')
const mockDirectory = 'mock'

app.use(mockMiddleware(mockDirectory))

Mock Data (under /mock)

/api/test.json => /api/test.json.js

module.exports = {
  success: true,
  msg: 'Hello, Node.js!'
}

// Using user-defined funciton
module.exports = function(req, res) {
  // http://expressjs.com/en/api.html
  res.json({
    success: true,
    msg: 'Hello, Node.js!'
  })
}

// Define different HTTP methods
module.exports = {
  __GET: {
    success: true,
    msg: 'Hello, Node.js!'
  },

  __POST: {
    success: 'true'
  }
}

About

A Http Mock Middleware for Express.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%