[MEAN Stack] First API -- 6. Using Express route instance
For server.js, we update the code by using route instance. By using this, we can remove some duplicate code.
For example:
app.get('/people', function(request, response){});
app.post('/people', parseUrlencoded, function(request, response){});
app.get('/people/:name', function(request, response){});
app.delete('/people/:name', function(request, response){});
There are a lot of '/people/'...
Using route instance:
app.route('/people')
.get(function(req ,res){})
.post(parseUrlEncoded, function(req, res){}); app.route('/people/:name')
.get(function(req, res){})
.delete(function(req, res){});
In our case:
before:
//server.js 'use strict'; var express = require('express');
var cors = require("cors");
var app = express();
app.use(cors());
var people = require('./controller/people'); app.get('/people', people.getAll);
app.get('/people/:id', people.get); app.listen(3000);
after:
'use strict'; var express = require('express');
var cors = require("cors");
var app = express();
app.use(cors());
var people = require('./controller/people'); app.route('/people')
.get(people.getAll);
app.route('/people/:id')
.get(people.get);
app.listen(3000);
[MEAN Stack] First API -- 6. Using Express route instance的更多相关文章
- [Express] Level 5: Route Instance -- refactor the code
Route Instance Let's rewrite our cities routes using a Route Instance. Create a new Route Instance f ...
- 如何在ARM中创建Express Route
很早之前就想试试Azure的express route,但是一直没有找到合适的机会,正好有个客户需要上express route,所以最近先自己研究研究,防止在做poc的时候耗费更多时间,本次场景我们 ...
- nodejs express route 的用法
express 中文社区:http://expressjs.jser.us/community.html nodejs express route 的用法 1. 首先是最基本的用法. 1 2 3 4 ...
- 一根Express Route同时支持ARM和ASM的VNET
ARM模式的Azure管理模式在China Azure上已经正式落地了.今后在China Azure上应该主要以ARM的模式创建VM了. 并且目前Express Route也已经可以在ARM模式下创建 ...
- ARM模式下创建Express Route
在Azure的ARM模式下,创建Express Route的命令和ASM模式下是有一些区别的. 本文将介绍在ARM模式下,如果创建Express Route的Circuit. 1. 查看支持的Serv ...
- Express Route的配置
ExpressRoute在中国已经Preview了. 本篇文章讲介绍ExpressRoute如何配置. Express Route的逻辑拓扑结构: 在配置Express Route之前,需要做VLAN ...
- 每日技术总结:promise,express route,评分,local storage商品浏览历史,
最近正在用Vue做一个电商项目.利用工作前后空隙时间. 1.promise的使用 点这里 如何在实际项目中使用Promise 2. Express Route 前后端传参的两种方法 (1)req.pa ...
- [MEAN Stack] First API -- 3. Select by ID with Mongoose and Express
Mongoose allows you to easily select resources by ID from your MongoDB. This is an important aspect ...
- [MEAN Stack] First API -- 1. with Node.js, Express and MongoDB
Learn how to import data into your MongoDB and then use Express to serve a simple Node.js API. Impor ...
随机推荐
- hdu 2825(ac自动机+状态压缩dp)
题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...
- 1047图的深度优先遍历c语言
描述 图(graph)是数据结构 G=(V,E),其中V是G中结点的有限非空集合,结点的偶对称为边(edge):E是G中边的有限集合.设V={0,1,2,……,n-1},图中的结点又称为顶点(vert ...
- redis错误汇总
1.redis因为内存不够而启动失败 Microsoft Open Tech group 在 GitHub上开发了一个REDIS Win64的版本,项目地址是:https://github.com/M ...
- linux 安装jdk 配置tomcat
Linux(ubuntu)下安装JDK.Tomcat 一.安装jdk 1)首先以root用户登录进去,在根目录下建立/usr/java的目录,我们将下载的东西都放到该目录下去. 2)参考的https: ...
- 常用SQL语句汇总整理
1.SQL 插入语句得到自动生成的递增ID 值 insert into Table1(Name,des,num) values (''ltp'',''thisisbest'',10); select ...
- 【九度OJ】题目1096-二分查找
题目1069:查找学生信息 这篇文章中提到的问题主要是由于调试平台Visual Studio和测试平台Online Judge的一些小差异,造成在Visual Studio中调试通过的代码,在输入OJ ...
- C++读取、旋转和保存bmp图像文件编程实现
以前也遇到过bmp文件的读写.这篇博客很好,写的其他内容也值得学习. 参考:http://blog.csdn.net/xiajun07061225/article/details/6633938 学 ...
- 一起刷LeetCode2-Add Two Numbers
今天看不进去论文,也学不进去新技术,于是先把题刷了,一会补别的. -----------------------------------------------------我才不是分割线------- ...
- 在fedora20下面手动为自己的安装程序创建桌面图标
(博客园-番茄酱原创) 在/usr/share/applications/下面创建destktop文件,用于产生桌面图标 创建文件:touch android-eclipse.desktop 编辑文件 ...
- BAT-使用BAT方法结束进程(删除进程)
@echo off taskkill /f /im GAM.exe taskkill /f /im GCL10.exe