0.1.0 • Published 6 years ago

pocket-server v0.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

pocket-server

Simple mock server as a node module. Helpful for development, testing purposes.

Usage

Response for all requests

const start = require('pocket-server');

// response for all requests

server.start(3000, [{
  response: {
    body: 'response body'
  }
}], config);

Filtering by path

const start = require('pocket-server');

// response for all requests

server.start(3000, [{
  request: {
    path: '/page'
  }
  response: {
    body: 'page content'
  }
}], config);

Error response

const start = require('pocket-server');

// response for all requests

server.start(3000, [{
  request: {
    path: '/submit'
  }
  response: {
    status: 400,
    body: 'Invalid data'
  }
}], config);

JSON response

const start = require('pocket-server');

// response for all requests

server.start(3000, [{
  request: {
    path: '/user'
  }
  response: {
    headers: {
      'Content-Type': 'application/json'
    },
    body: {
      name: 'John',
      age: 21
    }
  }
}], config);

start(port, mocks, config)

port - Number - port to listen

mocks - Array - array of mocks

config - Object - configuration object

0.1.0

6 years ago

0.0.2

6 years ago

0.0.2-alpha.1

6 years ago

0.0.1

6 years ago