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)
- Possible Incompleteness HOT 1
- Possible Incompleteness HOT 1
- doc: change `&ContentType` with `&Accept` in the list of implementations of `FromRequest` HOT 1
- [Feature]: Enhanced State Mutation for Effortless Handling of Shared Resources HOT 5
- Guide navigation causes relative links inside articles to 404 HOT 1
- Redirection to a route which takes a vector parameter results in an error HOT 1
- Allow users to create of Data<'r> objects HOT 5
- Validation not invoked on Json HOT 6
- Implement `FromForm` for `Range` HOT 1
- Missing license files in rocket_codegen-0.5.0.crate HOT 2
- Add SQLite extensions HOT 2
- Middleware that handles requests for static resources HOT 2
- Unable to build: no `Serialize` in `de` HOT 3
- Add default content_type for TempFile uploads HOT 2
- Could not find `json` in `serde` HOT 1
- Can't change IP that Rocket starts from. HOT 1
- Clippy lint: temporary with significant `Drop` can be early dropped HOT 1
- Rocket sometimes resets connection instead of responding with 413 error response HOT 2
- MiniJinja can't be used for templates HOT 1
- Routing by hostname HOT 10
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.