gre

gulp-rest-emulator

Gulp plugin for temrdm/rest-emulator

Showing:

Popularity

Downloads/wk

102

GitHub Stars

13

Maintenance

Last Commit

5yrs ago

Contributors

2

Package

Dependencies

9

Size (min+gzip)

268.0KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

gulp-rest-emulator

Join the chat at https://gitter.im/temrdm/gulp-rest-emulator

NPM

Installation

npm install --save gulp-rest-emulator

Links

Usage

Gulp

var gulp = require('gulp');
var restEmulator = require('gulp-rest-emulator');

gulp.task('run', function () {
    // Options not require
    var options = {
        port: 8000,
        root: ['./'],
        rewriteNotFound: false,
        rewriteTemplate: 'index.html',
        corsEnable: false, // Set true to enable CORS
        corsOptions: {}, // CORS options, default all origins
        headers: {}, // Set headers for all response, default blank
        httpsEnable: false, // Set true to enable HTTPS
        httpsOptions: {} // HTTPS options
    };
    return gulp.src('./mocks/**/*.js')
        .pipe(restEmulator(options));
});

gulp.task('watch', ['run'], function () {
    gulp.watch('./mocks/**/*.js', ['run']);
});

Mock

Example structure

mocks/ default.js users/ default.js custom.js cities/ default.js custom.js country.js

Mock syntax

Basic

module.exports = {
    '/api/users': {
        data: [
            { name: 'John' },
            { name: 'Adam' }
        ],
        headers: {}, // Headers for current preset, default blank
        code: 200, // Default value
        timeout: 0 // Default value in ms
    },
    '/api/cities': {
        data: [
            { name: 'New York' },
            { name: 'Miami' }
        ]
    }
};

Default

module.exports = {
    '/api/users': {
        GET: {
            data: [
                { name: 'John' },
                { name: 'Adam' }
            ],
            timeout: 100
        },
        POST: {
            data: {
                success: true
            },
            code: 201
        }
    }
};

Full (with presets)

module.exports = {
    '/api/users': {
        GET: {
            default: {
                data: [
                    { name: 'John' },
                    { name: 'Adam' }
                ],
                headers: {
                    XTag: 12345
                }
            },
            blank: {
                data: []
            },
            increase: {
                data: [
                    { name: 'John' },
                    { name: 'Adam' },
                    { name: 'Clark' },
                    { name: 'Earl' }
                ]
            }
        },
        POST: {
            default: {
                data: {
                    success: true
                },
                code: 201,
                timeout: 1000
            },
            error: {
                code: 405,
                timeout: 2000
            }
        }
    },
    '/api/cities': {
        'GET': {
            data: [
                { name: 'New York' },
                { name: 'Miami' }
            ]
        }
    }
};

Query params

module.exports = {
    '/api/users': {
        GET: {
            data: [
                { name: 'John' },
                { name: 'Adam' }
            ],
            headers: {
                XTag: 12345
            },
            query: {
                // Usage: /api/users/?name=Adam
                'name=Adam': {
                    data: [
                        { name: 'Adam' }
                    ],
                    headers: {
                        XTag: 54321
                    }
                },
                // Usage: /api/users/?name='John Doe'
                'name=John Doe': {
                    data: [
                        { name: 'John Doe' }
                    ]
                }
            },
            timeout: 100
        }
    }
};

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100