json-server makes it extremely easy to setup robust JSON apis to use for demos and proof of concepts. John walks you through the process of using pre-built json files for a server and how to generate larger datasets using lodash and faker.

Install:

npm install -g json-server

Create a json file:

{
"people": [
{
"id": 0,
"name": "John"
}
]
}

Run:

json-server db.json

It will run the localhost:3000:

It return the data:

[{"id":0,"name":"John"}]

or db:

{"people":[{"id":0,"name":"John"}]}

You also can do POST; DELETE; GET;

For example POST:

After I post twice, we got three results:

[{"id":0,"name":"John"},{"name":"Yuri","id":1},{"name":"Yuri","id":2}]

We can UPDATE the last one also:

Get more data to play with:

/**
* Created by Answer1215 on 1/13/2015.
*/
module.exports = function() {
var faker = require('faker');
var _ = require('lodash'); return {
people: _.times(100, function(n) {
return{
id: n,
name: faker.name.findName(),
avater: faker.internet.avatar()
}
})
}
}

Query

[Node.js] Creating Demo APIs with json-server的更多相关文章

  1. [译]Node.js : Building RESTful APIs using Loopback and MySQL

    国庆后可能就要使用StrongLoop那套东西来做项目了 原文:http://www.javabeat.net/loopback-mysql/ Loopback是什么? Loopback是一个开源的N ...

  2. node.js连接本地数据库及json返回数据

    新建一个文件夹node.js,目录下打开命令初始化一下 cnpm init 然后下载express框架 cnpm install express --save 接着下载数据库的依赖 cnpm inst ...

  3. Code Your First API With Node.js and Express: Set Up the Server

    How to Set Up an Express API Server in Node.js In the previous tutorial, we learned what the REST ar ...

  4. [node.js 学习]1.start a simple server

    1.启动一个本地的服务 下面是官方的例子,会生成一个随机端口,返回的是纯文本: var net = require('net'); var server = net.createServer((soc ...

  5. node.js之看懂package.json依赖库版本控制

    金天:学习一个新东西,就要持有拥抱的心态,如果固守在自己先前的概念体系,就会有举步维艰的感觉.node.js依赖库的版本控制 一般node.js项目会依赖大量第三方module, 那么如何控制modu ...

  6. [整理]Node入门 » 一本全面的Node.js教程 - Demo实践所遇到的问题

    花了一个上午看完[转载]Node入门 » 一本全面的Node.js教程 根据里面的Demo自己手动实现过程中还是遇到了些问题,特整理在此. <1>.由于node.msi安装包已经自动添加了 ...

  7. [Node.js] Creating JWTs (JSON Web Tokens) in Node

    In this lesson we will look at all of the pieces that combine together to create a JWT (j AWT) or JS ...

  8. Node.js学习笔记(三) --- package.json 及cnpm

    一.包 Nodejs   中除了它自己提供的核心模块外,我们可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依赖关系的模块进行统一管理. 完全符合 ...

  9. Node.js NPM Package.json

    章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json Nod ...

随机推荐

  1. 函数page_get_space_id

    #define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID  34 /****************************************************** ...

  2. Spring Data JPA初使用

    我们都知道Spring是一个非常优秀的JavaEE整合框架,它尽可能的减少我们开发的工作量和难度. 在持久层的业务逻辑方面,Spring开源组织又给我们带来了同样优秀的Spring Data JPA. ...

  3. php编译参数注解--不明白许多参数的作用 慎用 –with-curlwrappers参数

    在Linux下安装PHP,源代码方式安装,总需要配置很多参数.这里列出常用配置参数,并详细用中文解释说明了.给大家一些参考 编译PHP的时候慎用 –with-curlwrappers参数 ./conf ...

  4. word2010中莫名出现灰色中括号解决方案

    灰色中括号[]是文中书签,解决方案: word 文件-选项-高级,在“显示文档内容”部分,去掉“显示书签”前面的勾选.

  5. erlang判断语法结构:if/case/guard

    erlang 有好几种常用的判断结构语句,如 if.case.guard 等.文章将分别对 if / case /guard 的特点做介绍,以及用例说明 1.if 结构 if Condition 1  ...

  6. dojo(五):Dijit-基本组件

    转自:http://blog.csdn.net/trendgrucee/article/details/12679949 1.简介 Dijit是Dojo的UI框架,包含一系列丰富的组件以帮助你快速开发 ...

  7. HDU 5317 RGCDQ

    题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少. 解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计 ...

  8. 《深入Java虚拟机学习笔记》- 第2章 平台无关

    Java虚拟机学习笔记(二)平台无关

  9. 第一章 Lambda表达式

    1.1 Why Lambdas? 当你操作多线程的时候,你会像下面这样将要处理的代码放到run()函数中: class Worker implements Runnable { public void ...

  10. opencv 在工业中的应用:blob分析

    在工业中经常要检测一副图像中物体的数量,位置,大小,面积等信息,这就要用到BLOB分析,我用OPENCV做了个BLOB分析的DEMO. (1)打开一幅图像 (2)进行参数设置,设定二值化阙值,并选择是 ...