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. 解决java switch……case不能匹配字符串的问题

    java1.7已经支持了匹配字符串 方案1. enum Animal { dog,cat,bear; public static Animal getAnimal(String animal){ re ...

  2. 【转】目前最细致清晰的NSDictionary以及NSMutableDictionary用法总结 -- 不错

    原文网址:http://www.cnblogs.com/wengzilin/archive/2012/03/15/2397712.html 做过Java语言 或者 C语言 开发的朋友应该很清楚 关键字 ...

  3. HTML5桌面通知:notification api

    1. 为什么需要HTML5的桌面通知 传统的桌面通知可以写一个div放到页面右下角自动弹出来,并通过轮询等等其他方式去获取消息并推送给用户.这种方式有个弊端就是:当我在使用京东 进行购物的时候,我是不 ...

  4. AM335x(TQ335x)学习笔记——挂载Ramdisk

    上篇文章中我们已经能够通过u-boot启动内核了,但是没有能够启动成功,从内核的log中可以看出,内核启动失败的原因是没有挂载到root文件系统,本文将使用busybox制作根文件系统并打包成ramd ...

  5. POJ 2001-Shortest Prefixes(Trie 入门)

    题意:给你一组串,求每个串在组中唯一标志的最短前缀 分析:保存树上经过各节点的单词个数,扫描每个串当经过节点单词个数是一(能唯一标志)结束 #include <map> #include ...

  6. 多线程与网络之JSON和XML数据的解析

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  7. 2015年10月23日JS笔记

    ECMAScript标准:JavaScript核心语法 微软:Jscript ECMAScript标准:一纸空文 JavaScript和JScritp都号称完全实现了 ECMAScript标准 W3C ...

  8. MFC用PostMessage传递消息

    1.自定义消息ID. #define WM_MY_MESSAGE (WM_USER+100)         WM_USER为windows系统为非系统消息保留的ID,这里至少要用100,因为其它控件 ...

  9. Esper系列(十四)Contained-Event Selection

    功能:该语法是针对所查询事件中的属性又是另一种属性的查询结果控制. 格式: 1  "+j); 19      bean.setBean(item); 20      list.add(bea ...

  10. HW6.17

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...