[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 ...
随机推荐
- 使用委托的BeginInvoke方法来完成复杂任务的操作
现在假设我有这样一个窗体(包含一个进度条和一个按钮与两个文本框),在第一个文本框中输入一个数字进行阶乘运算,在此过程中进度条与运算进度保持一致,同时可以在第二个文本框中进行其它工作(比如输入).对付这 ...
- SCOI2009游戏
1025: [SCOI2009]游戏 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1065 Solved: 673[Submit][Status] ...
- android广告平台介绍
广告模式: 广告条:最普遍的广告模式,嵌入在应用界面内,用户点击行为会带来收入. 积分墙:应用通过限制功能.去广告等引导用户进入积分墙页面下载广告应用得到积分来换取使用的模式,用户安装完推荐广 ...
- POJ 2001 字典树(入门题)
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #i ...
- [JDBC-1] JDBC Base Template
以Statement建立的标准模板: static void template() throws Exception { Connection conn = null; Statement st = ...
- Puppet学习:pp文件权限问题
由于内网的Puppet还是在测试中,所以对文件权限等内容未做过多关注. 今天报了错误: Error: Could not retrieve catalog from remote server: Er ...
- leetcode@ [318] Maximum Product of Word Lengths (Bit Manipulations)
https://leetcode.com/problems/maximum-product-of-word-lengths/ Given a string array words, find the ...
- asp.net(C#) 中 怎么使用 MongoDb
1. 先引用以下Dll(如果找不到 到gethub上下载源代码自己编译 特别是MongoDB.Driver.Legacy.dll 我自己找了半天没找到): MongoDB.Bson.dll Mongo ...
- mac 学习
1. 下载下来的eclipse,想把eclipse的图标放到applications目录里 做法:将下载的eclipse 的gz 文件直接移动到 /Applications 文件夹下 ,解压后即可在 ...
- BroadcastReceiver学习笔记
1.在代码中注册与在AndroiManifest.xml注册的区别 (a)在代码中注册可以控制注册与注销的时间.比如在onCreate-onDestory, onStart-onStop, onRes ...