How to use the fakerest.Server function in fakerest

To help you get started, we’ve selected a few fakerest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marmelab / ng-admin-demo / js / api.js View on Github external
var FakeRest = require('fakerest');
var sinon = require('sinon/lib/sinon/util/fake_server');

var restServer = new FakeRest.Server();
restServer.toggleLogging();
restServer.init(data);

sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url) {
    // Do not catch webpack sync, config.js transformation but catch /upload in test env
    return url.indexOf('/socket.io/') !== -1 || url.indexOf('config.js') !== -1;
});

var server = sinon.fakeServer.create();
server.autoRespond = true;
server.autoRespondAfter = 0; // answer immediately
server.respondWith(restServer.getHandler());
github front / storypage / src / globals / api-request / index.js View on Github external
case `${apiRoot}/users`:
      case `${apiRoot}/users/`:
        if (method === 'GET') {
          res = Actions.fetchAuthors();
        }
    }

    if (res) {
      // fake REST server only need expected data on response
      const data = {
        [ resource ]: singleResource ? [ res.payload ] : map(res.payload),
      };

      if (data) {
        // initialize fake REST server
        const restServer = new FakeRest.Server();
        restServer.init(data);

        // use sinon.js to monkey-patch XmlHttpRequest
        const server = sinon.fakeServer.create();
        server.respondWith(restServer.getHandler());

        // faking a request
        const url = singleResource ? `/${resource}/${res.payload.id}` : `/${resource}`;
        const xhr = new XMLHttpRequest();

        // always a GET (changes are already done)
        xhr.open('GET', url, false);
        xhr.responseType = 'json';
        xhr.send(null);

        // restore native XHR constructor
github yhtml5 / yhtml5-tutorial / AngularJS / demo / ng-admin-first / node_modules / ng-admin / examples / ng-admin-demo / js / api.js View on Github external
var FakeRest = require('fakerest');
var sinon = require('sinon/lib/sinon/util/fake_server');

var restServer = new FakeRest.Server();
restServer.toggleLogging();
restServer.init(data);

sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url) {
    // Do not catch webpack sync, config.js transformation but catch /upload in test env
    return url.indexOf('/socket.io/') !== -1 || url.indexOf('config.js') !== -1;
});

var server = sinon.fakeServer.create();
server.autoRespond = true;
server.autoRespondAfter = 0; // answer immediately
server.respondWith(restServer.getHandler());
github marmelab / react-admin / packages / ra-data-fakerest / src / index.ts View on Github external
export default (data, loggingEnabled = false): DataProvider => {
    const restServer = new FakeRest.Server();
    restServer.init(data);
    if (window) {
        // give way to update data in the console
        (window as any).restServer = restServer;
    }

    function getResponse(type, resource, params) {
        switch (type) {
            case 'getList': {
                const { page, perPage } = params.pagination;
                const { field, order } = params.sort;
                const query = {
                    sort: [field, order],
                    range: [(page - 1) * perPage, page * perPage - 1],
                    filter: params.filter,
                };
github marmelab / aor-json-rest-client / src / index.js View on Github external
export default (data, loggingEnabled = false) => {
    const restServer = new FakeRest.Server();
    restServer.init(data);

    function getResponse(type, resource, params) {
        switch (type) {
        case GET_LIST: {
            const { page, perPage } = params.pagination;
            const { field, order } = params.sort;
            const query = {
                sort: [field, order],
                range: [(page - 1) * perPage, (page * perPage) - 1],
                filter: params.filter,
            };
            return {
                data: restServer.getAll(resource, query),
                total: restServer.getCount(resource, { filter: params.filter }),
            };
github marmelab / react-admin / example / RestClient.js View on Github external
export default (data, loggingEnabled = false) => {
    const restServer = new FakeRest.Server();
    restServer.init(data);

    function getResponse(type, resource, params) {
        switch (type) {
        case GET_LIST: {
            const { page, perPage } = params.pagination;
            const { field, order } = params.sort;
            const query = {
                sort: [field, order],
                range: [(page - 1) * perPage, (page * perPage) - 1],
                filter: params.filter,
            };
            return {
                data: restServer.getAll(resource, query),
                total: restServer.getCount(resource, { filter: params.filter }),
            };

fakerest

Patch XMLHttpRequest to fake a REST server based on JSON data.

MIT
Latest version published 3 months ago

Package Health Score

72 / 100
Full package analysis

Popular fakerest functions

Similar packages