Comments (16)
@kestred The reason I'd like to use different syntax here is to differentiate between the arity of the collection. I propose that <...>
is always 1-ary, as it is now, while {...}
is used for n-ary collections of parameters. Thus, {param1, param2}
is valid while <param1, param2>
is not.
from rocket.
Will wait to see if others would like this as well. I generally don't use query strings, so this is low in my personal bucket-list.
from rocket.
Definitely a desirable feature, doing parsing with structs is obviously cleaner in a lot of cases, but for quick prototyping of methods this would be invaluable.
from rocket.
I'd like to have such feature because it is very useful. e.g. in my current project we use pagination as query params like perPage and currentPage so it'd be nice to avoid creating 2 struct and just use primitive.
from rocket.
I would find this feature helpful; I actually expected it to work this way after switching from a path parameter (like #[post(/<blah>")] fn blah(blah: String)
to a query parameter #[post(/?<blah>")] fn blah(blah: String)
.
I notice you recommended using syntax {blah}
for plain params vs <blah>
, however I would expect that the latter would have worked with anything implementing FromParam.
Possibly there could be multiple varieties (like <var>
for FromParam, {var}
for FromData, and [var]
for FromForm) but I don't like that solution too much because the syntax would feel somewhat arbitrary?
from rocket.
This would certainly be useful. It would also be nice of the param could be converted from camel case to snake case automatically during this process.
So ex, a param comes in as MyParam but you specify fn(my_param: String). (Ex, twilio uses camel case when it submits a request)
from rocket.
Does this also imply that it is not possible to have one function handle URLs with and without a query string?
I have
#[post("/events?<query>", data = "<events>")]
But even though the struct that query
goes into is just an Option<String>
, it won't match /events
from rocket.
@SergioBenitez Would consider support multi query params ? #[get("/hello?<p1><p2>")] or #[get("/hello?{<p1>, <p2>}")]
from rocket.
@sickHamm Imagine both struct p1 and p2 both having a field of the same name. Who gets the value? Do they both? Suppose Rocket could check at compile time to make sure structs p1 and p2 wouldn't conflict.
from rocket.
@sickHamm How does that differ from what's being proposed here via path?{p1, p2}
?
from rocket.
@sickHamm Doesn't. :D
from rocket.
while {...} is used for n-ary collections of parameters. Thus, {param1, param2} is valid
struct P1 { ...};
struct P2 {...};
#[get("/hello?{p1,p2}")]
fn hello(p1: P1, p2: P2)
is valid?
In my opinion {p1, p2}
mean p1, p2 both "simple" type that impl FromFormValue
;
{<p1>, <p2>}
mean <p>
is ”complex” type must impl FromForm
.
from rocket.
if <> just mean 1-ary collections and {} is used for n-ary collections ; what differ {p1}
via <p1>
,
and above example should be valid, so just a simple usage would have many problem as @lholden say;
from rocket.
Accepting this and slating it for 0.5.
from rocket.
Accepted for 0.4. Tracked in #608 as part of the new query-string handling.
from rocket.
It is not invalid to have the same param name appear multiple times in a query string "arg=1&arg=2"
How is this handled?
Also re how that interrelates to params passed in the body - what does the spec say? is the spec is silent then what do other frameworks do?
from rocket.
Related Issues (20)
- `uri!` macro does not accept routes defined as constants HOT 5
- Cors docs and examples HOT 1
- Path to `contrib` repositories is not correct in sub `Cargo.toml` files HOT 1
- Force enable color output HOT 2
- Getting several lints on a #[derive(FromForm)] HOT 1
- Receiving ">>> Request guard `…` is forwarding" messages with log_level=critical HOT 6
- debug!("Received request: {:#?}", hyp_req); HOT 4
- Can't make private cookie not secure HOT 4
- Rocket does not return a 413 when the data submitted in a form exceeds the limit HOT 7
- Build fails with rustc<=1.68.2 HOT 3
- Update `hyper` to `1.0` HOT 1
- Conflicts among routes when `FileServer::rank()` function is used HOT 11
- Getting several no_effect_underscore_binding lints on #[launch] HOT 1
- Hello world example compiler error: macro-expanded `macro_export` HOT 2
- Handling of null bytes in forms is problematic HOT 6
- Improvements for the web serach: Content-Type, text/plain HOT 4
- Phase out async_trait macro HOT 2
- Recognise source maps in `ContentType::from_extension` HOT 2
- route rank clarification HOT 1
- Link to GitHub discussion from the web site 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 rocket.