Git Product home page Git Product logo

web-server-mock's Introduction

此项目已不再维护,推荐使用 https://github.com/typicode/json-server

This project is no longer maintained, it is recommended that you use https://github.com/typicode/json-server

WEB SERVER MOCK

此项目在Web-server.js的基础上,增加模拟restful api的支持,提供前端开发的模拟数据支撑。

Web-server.js 是之前github找到的一个项目中携带的,现在忘记出处了,在这里感谢原作者。

安装方式:

本项目依赖 nodejs,请先安装

安装到全局:

$ npm install -g web-server-mock

使用方法:

在项目目录下: 使用 $ wsm 或者 $ wsm 8000 指定端口号,启动服务。

./mockdata/api.js 复制到项目目录,修改其中测试数据。你可以在目录中添加多个*.js文件

模拟数据范例

(function(){
	var _list = [{id:'abc',value:'ABC'},{id:'efg',value:'EFG'}]
	var _api = {
		list: query
	}

	function query(url){
		var params = url.replace('/api/list','').split('/');

		if(params.length == 1 )
			return _list;

		for (var i = 0,len = _list.length; i < len; i++) {
			var item = _list[i];
			if(item.id === params[1]){
				return item;
			}
		};

		return null;
	}

	return _api;

})()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.