JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1696
  • Score
    100M100P100Q126732F
  • License MIT

Pretty simple mocks for the CRUD and REST API

Package Exports

  • superagent-mocker

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (superagent-mocker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

superagent-mocker

Build Status

REST API mocker for the browsers. LOOK MA NO BACKEND! 👐

Written for superagent.

Install

npm i superagent-mocker

Usage

Setup

var request = require('superagent');
var mock = require('superagent-mocker')(request);

Get

mock.get('/topics/:id', function(req) {
  var id = req.params.id;
  return { id: req.params.id, content: 'Hello World!' };
});

request
  .get('/topics/1')
  .end(function(err, data) {
    console.log(data); // { id: 1, content: 'Hello World' }
  })
;

Post

mock.post('/topics/:id', function(req) {
  return {
    id: req.params.id,
    content: req.body.content
  };
});

request
  .post('/topics/5', { content: 'Hello world' })
  .end(function(err, data) {
    console.log(data); // { id: 5, content: 'Hello world' }
  })
;

mock.put() and mock.del() methods works as well.

Note

Sadly, but request.send() doesn't work :( Sorry

License

MIT © Shuvalov Anton