Express 4中不推荐使用的req.param()的替换 [英] Replacement for req.param() that is deprecated in Express 4

查看:131
本文介绍了Express 4中不推荐使用的req.param()的替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从ExpressJS 3迁移到ExpressJS 4,并且我们注意到不推荐使用以下API:

We are migrating from ExpressJS 3 to ExpressJS 4, and we noted that the following APIs are being deprecated:

req.param(fieldName)
req.param(fieldName, defaultValue)

是否有中间件将这些API带回来,就像从Express到独立模块被外部化"的其他API一样?

Is there a middleware that brings these APIs back, like other APIs that were 'externalized' from express to independent modules ?

澄清-需要一个API,该API提供对参数的抽象通用访问,无论它是路径参数,查询字符串参数还是主体字段.

EDITED: Clarification - The need is an API that provides an abstracted generic access to a parameter, regardless to if it is a path-parameter, a query-string parameter, or a body field.

推荐答案

好吧,在阅读@Ineentho在引用中给出的线程之后,我们决定想出以下答案:

Ok, after reading the threads given in references by @Ineentho, we decided to come up with the following answer:

https://github.com/osher/request-param

一种连接/表达中间件,用于启用Express 4中弃用的req.param(名称,默认)API.

A connect/express middleware to enable back the req.param(name,default) API deprecated in express 4

中间件不仅恢复了古旧的功能. 它还可以让您 自定义从中检索参数的集合的顺序 ,既可以作为默认规则,也可以按调用:-)

The middleware does not only brings back the goo'old functionality. It also lets you customize the order of collections from which params are retrieved , both as default rule, and as per-call :-)

玩得开心!

这篇关于Express 4中不推荐使用的req.param()的替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆