• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

temrdm/gulp-rest-emulator: Gulp plugin for temrdm/rest-emulator

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

temrdm/gulp-rest-emulator

开源软件地址(OpenSource Url):

https://github.com/temrdm/gulp-rest-emulator

开源编程语言(OpenSource Language):

JavaScript 90.9%

开源软件介绍(OpenSource Introduction):

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
        }
    }
};



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
yoeran/kirby-kit: Kirby CMS starter kit with Gulp发布时间:2022-06-21
下一篇:
clkao/gullet: A taskbar app for building gulp projects发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap