[Node.js] Creating Demo APIs with json-server
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的更多相关文章
- [译]Node.js : Building RESTful APIs using Loopback and MySQL
国庆后可能就要使用StrongLoop那套东西来做项目了 原文:http://www.javabeat.net/loopback-mysql/ Loopback是什么? Loopback是一个开源的N ...
- node.js连接本地数据库及json返回数据
新建一个文件夹node.js,目录下打开命令初始化一下 cnpm init 然后下载express框架 cnpm install express --save 接着下载数据库的依赖 cnpm inst ...
- 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 ...
- [node.js 学习]1.start a simple server
1.启动一个本地的服务 下面是官方的例子,会生成一个随机端口,返回的是纯文本: var net = require('net'); var server = net.createServer((soc ...
- node.js之看懂package.json依赖库版本控制
金天:学习一个新东西,就要持有拥抱的心态,如果固守在自己先前的概念体系,就会有举步维艰的感觉.node.js依赖库的版本控制 一般node.js项目会依赖大量第三方module, 那么如何控制modu ...
- [整理]Node入门 » 一本全面的Node.js教程 - Demo实践所遇到的问题
花了一个上午看完[转载]Node入门 » 一本全面的Node.js教程 根据里面的Demo自己手动实现过程中还是遇到了些问题,特整理在此. <1>.由于node.msi安装包已经自动添加了 ...
- [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 ...
- Node.js学习笔记(三) --- package.json 及cnpm
一.包 Nodejs 中除了它自己提供的核心模块外,我们可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依赖关系的模块进行统一管理. 完全符合 ...
- Node.js NPM Package.json
章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json Nod ...
随机推荐
- Thread: BooleanRT : Realtime 3D boolean operations for (Runtime,Editor)
A Product by Mixed Dimensions What is BooleanRT? BooleanRT is a real-time 3D boolean operations exte ...
- 在Linux上运行C#
众所周知,C#是Microsoft推出的.NET语言,只能在.NET平台上运行,例如Win 9x.ME.NT.2000.XP和Win CE之类的操作系统.但是,现在却有了一个叫做Mono的项目,它的目 ...
- iframe控件
function goTo(url) { document.getElementById("iframeid").src = url; //获得要显示的页面,当点击时就会在ifra ...
- Cacti 'graph_xport.php' SQL注入漏洞
漏洞版本: Cacti < 0.8.8b 漏洞描述: Bugtraq ID:66555 Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具. Cact ...
- ☀Chrome模拟移动端浏览器
- 【原创】深度神经网络(Deep Neural Network, DNN)
线性模型通过特征间的现行组合来表达“结果-特征集合”之间的对应关系.由于线性模型的表达能力有限,在实践中,只能通过增加“特征计算”的复杂度来优化模型.比如,在广告CTR预估应用中,除了“标题长度.描述 ...
- [NOI导刊2011]影像之结构化特征
问题描述 在影像比对中,有一种方法是利用影像中的边缘(edge)资讯,计算每个边缘资讯中具有代表性的结构化特征,以作为比对两张影像是否相似的判断标准.Water-filling方法是从每个边缘图的一个 ...
- IRP_MJ_CREATE
原文链接:http://laokaddk.blog.51cto.com/368606/125553/ MSDN:https://msdn.microsoft.com/library/windows/h ...
- JDK1.5新特性(六)……Generics
概述 Generics - This long-awaited enhancement to the type system allows a type or method to operate on ...
- RxJava 复杂场景 Schedulers调度
参考: https://blog.piasy.com/2016/10/14/Complex-RxJava-2-scheduler/ 以Zip为例,学习Schedulers的线程调度 要求: * cre ...