[MEAN] 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);
时间: 2024-10-12 16:27:12

[MEAN] 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 for the '/cities' URL path and assign it to thecitiesRoute variable. var citiesRoute = app.route('/cities'); Move the code from our previous app.get() 

Express Route的配置

ExpressRoute在中国已经Preview了. 本篇文章讲介绍ExpressRoute如何配置. Express Route的逻辑拓扑结构: 在配置Express Route之前,需要做VLAN和IP地址的规划: Router IP Prefix Peering VLAN ID Primary 172.16.1.0/30 Private 555 Secondary 172.16.2.0/30 Private 555 Primary 172.16.1.4/30 Public 556 Seco

一根Express Route同时支持ARM和ASM的VNET

ARM模式的Azure管理模式在China Azure上已经正式落地了.今后在China Azure上应该主要以ARM的模式创建VM了. 并且目前Express Route也已经可以在ARM模式下创建,并支持ARM的VNET了. 如果客户有需求,要求Express Route的服务既支持ARM模式,又支持ASM模式,这时就需要在ARM模式的Express Route下开启ARM的Express Route支持Class VNET的功能. 具体的命令如下: $ckt = Get-AzureRmEx

nodejs express route 的用法

July 3rd, 2012 nodejs express route 的用法 1. 首先是最基本的用法. 1 2 3 4 5 var app=require('express').createServer();                                                     app.get("/",function(req,res){                                                        

通过openswan基于Azure平台搭建VPN server

用过Azure的读者都知道,Vnet一直是Azure比较自豪的地方,尤其是VPN,Azure提供了两种VPN以及专线来保证客户数据的安全性,S2S vpn(站点到站点的,基于IPsec的),P2S vpn(点到站点的,基于sstp的),专线express route是和物理链路或者MPLS网络相连接,在这里笔者要提醒大家一句,Azure的vpn身后是两台机器做HA的vpn server,是提供LSA保证的,而无论是阿里还是AWS都没有这样的服务,而且Azure最高提供带宽200M的VPN链路,三

MEANJS DOC

Overview Thank you for downloading the MEAN.JS boilerplate! This simple documentation will cover the basics of developing your MEAN application. Before you begin we recommend you read about the basic building blocks that assemble a MEAN.JS applicatio

Azure通过Vnet Peering和用户自定义路由(UDR)实现hub-spoken连接

Azure的Vnet Peering可以把Azure中不同的Vnet连接起来的技术.底层是通过对NVGRE的租户标签进行修改,实现了不同租户间的互通.这种技术非常类似传统网络中MPLS/VPN不同租户互通的技术.在MPLS/VPN中是对RT值进行控制,实现不同租户间的互通. 但Vnet Peering有一个限制:VNet 对等互连存在于两个 VNet 之间,多个对等互连之间没有任何派生的可传递关系.例如,如果 VNetA 与 VNetB 对等互连,VNetB 与 VNetC 对等互连,但 VNe

网站后端_Python+Flask.0006.FLASK地址转换之默认转换与自定义转换?

动态规则: 说明: URL规则可添加变量部分,也就是说将符合同种规则的URL抽象成一个URL模式 @app.route('/instance/<uuid>/') def instance(uuid):     return 'Instance: {}'.format(uuid) 注意: 尖括号中内容是动态的,凡是匹配到/instance/前缀的都会被映射到这个路由上,在内部把uuid作为参数而获得,默认类型为字符串 默认转换: 说明: 可通过<converter:variable_nam

网站后端_Python+Flask.0007.FLASK构造跳转之301跳转与302重定向?

构造地址: 说明: FLASK支持通过视图函数及传参来构造URL,而且未来修改URL可一次性修改,且默认构建会转义特殊字符和Unicode数据,这些工作不需要我们自己处理,且不仅支持在上下文中构造而且还支持在模版文件中构造 #!/usr/bin/env python # -*- coding: utf-8 -*- """ # # Authors: limanman # 51CTOBG: http://xmdevops.blog.51cto.com/ # Purpose: #