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. memcpy与memmove区别

    头文件:#include <string.h> memmove() 用来复制内存内容,其原型为:    void * memmove(void *dest, const void *src ...

  2. Glimpse

    给自己程序配好Glimpse. Glimpse.Mvc 有问题 遇到稍微复杂点的内套多个PartialView,内存就爆了彪1.7g,不开Glimpse一点问题都没.另外Glimpse.Nlog也有问 ...

  3. NoSql数据库使用半年后在设计上面的一些心得 (转)

    http://www.cnblogs.com/AllenDang/p/3507821.html NoSql数据库这个概念听闻许久了,也陆续看到很多公司和产品都在使用,优缺点似乎都被分析的清清楚楚.但我 ...

  4. 使用RMAN迁移文件系统数据库到ASM

    --================================== -- 使用RMAN迁移文件系统数据库到ASM --================================== 在实际 ...

  5. Warning: Name is nonexistent or not a directory

    Every time I start up MATLAB, I receive this message: Warning: Name is nonexistent or not a director ...

  6. c#编程指南(四) 组元(Tuple)

    (1).C#语法中一个个问号(?)的运算符是指:可以为 null 的类型. MSDN上面的解释: 在处理数据库和其他包含不可赋值的元素的数据类型时,将 null 赋值给数值类型或布尔型以及日期类型的功 ...

  7. Google Maps API v2 Demo Tutorial

    申请API KEY https://code.google.com/apis/console/?noredirect 1. 创建项目,名称随意,只是为了区分 2. 开启Google Maps Andr ...

  8. 如何升级cordova插件

    cordova-plugin-code-push插件在cordova6.1.1 ios环境中出现异常. 所以尝试升级cordova-plugin-code-push来解决这个问题. 升级没有被依赖的插 ...

  9. HDU 5335 Walk Out

    题意:在一个只有0和1的矩阵里,从左上角走到右下角, 每次可以向四个方向走,每个路径都是一个二进制数,求所有路径中最小的二进制数. 解法:先bfs求从起点能走到离终点最近的0,那么从这个点起只向下或向 ...

  10. cubla sample-code

    cublasSscal //Example 1. Application Using C and CUBLAS: 1-based indexing #include <stdlib.h> ...