Comments (2)
Salvo 中的 Router 本身是嵌套的,路径只是 Router 中的一个 Filter,所以,是给 Router 命名还是给 Router 中的路径命名?如果Router 不包含 Path 的 Filter 呢?如果多个 Router 存在相同的路径,是都起同样的名字? 会不会很怪异?会不会路径不同又有相同名字?如何检测冲突?
感觉不好实现,也没太大的意义。
from salvo.
很有意义的,对于微服务还好,路由少,如果是一个相对复杂的项目,比如一个电商吧,涉及的路由就很多了,后端经常需要生成url,返还给前端,这个时候,去拼凑uri就很麻烦了, 很多类似的框架都有这种功能,其实有个简单的办法,就是PathFilter里的字段给pub,或者将PathParser给设置成pub,这样就可以重新parse,类似:
let filter = PathFilter::new("/api/v1/test/handle_filter_path/guid:my_custom_guid/edit")
因为PathFilter内部自己调用了PathParser,也就无法进行进一步的获取计算了,代码被写死了,
这样,可以自己扩充request trait的方法,增加一个uri拼凑路由,这样就不需要router name了
比如重写一个
#[handler]
// https://0.0.0.0/edit/<user_id>/<article_id>?ref=test_user&ref_code=abc123
async fn handle_edit(req: &mut Request, res: &mut Response) {
// before url https://0.0.0.0/edit/10/5?ref=test_user&ref_code=abc123
let params = HashMap::from([("user_id", "1"), ("article_id","100")]);
let queries = HashMap::from([("ref", "admin"), ("ref_code","11111111")]);
let url = req.make_uri(req, params, queries);
// or let url = req.make_uri(“/edit/<user_id>/<article_id>”, params, queries);
// after url = https://0.0.0.0/edit/1/100?ref=admin&ref_code=11111111
res.render(Text::Json(
json!({
"code": 200,
"success": true,
"payload": {
"redirect_url": url
}
})
.to_string(),
))
}
from salvo.
Related Issues (20)
- OAPI : #[salvo(schema(name = XXX))] expects an identifier instead of a "string" literal HOT 7
- OAPI : Short FlexNamer doesn't respect schemas name HOT 3
- `oapi::ToParameters` trait requires `oapi::Extractible` trait, which is not necessary HOT 1
- Error display in `StatusError` implementation
- 使用PathParam时,路由通配符<**id>不生效 HOT 3
- Rename Affix HOT 6
- Server Logs Only Show HTTP/1.1 with `http2-cleartext` Feature in `salvo` Crate HOT 3
- Additionally, even when I disable the `http2` feature, the server still handles HTTP/2 requests. I don't think it should behave this way. HOT 10
- Sentry documentation
- OpenAPI page does not render
- Rename hoop HOT 5
- Add compression support to websockets HOT 2
- Derive `ToSchema` not work for unit enum variants
- 根据例子设置自定义页面404,发现res.status_code 一直是None HOT 1
- session 失效了
- 0.71.1: cannot call non-const fn `Identity::new` in constant functions HOT 2
- Force HTTPS
- Provide ability to setup Content-Type for each file or type in StaticDir HOT 1
- 静态文件服务用不了。按照文档上的写。没有use salvo::serve_static::StaticDir;中的serve_static没有 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from salvo.