Thruster
Thruster copied to clipboard
[FEATURE REQUEST] Add example for parse and validate a JSON body and query params
The current doc works with a string body, and the example that would help, the error handle one, don't touch the body.
Filling a form is a basic example for servers, and we can have the most used RESTful CRUD functionality:
- some data from a param (i.e.
DELETE /user/:id
), currently covered for example in:
https://github.com/thruster-rs/Thruster/blob/d80cf36ca3f8f40324dc5325a3c150aa5c833953/thruster/examples/mutable_state.rs#L37-L45
(Not sure if there is a "short form"? Maybe like a HashMap context.params
?)
-
some data from a query param (i.e.
GET /users?limit=12&page=2&query=Tom
), available as the HashMapcontext.query_params
but not shown in examples. -
data from a body (i.e. in
POST /user
) with a form data like
{
name: "Bob",
surname: "Sponge",
company: "Krusty Crab",
skills: ["annoying giggles", "cook patties", "karate"],
inventory: { clothes: ["pants", "shirt"], huntingNets: 2 }
}
(Note it has inner objects)
I am aware of context.get_body()
but it is a String and most people just starting to know thruster would expect a way to parse into JSON.
I think that including examples that cover such cases, like the JSON body, would help people implement thruster for web servers or other cases.
Request
- Include examples of parsing a JSON body
- (OPTIONAL) Includes example validating required and optional fields in the body. Not sure if posible using
serde
? - Include an example of getting query params from a request
Sorry for the delay, I'll get around to this and the other examples this weekend! Thanks for pointing it out -- I can't believe I don't have a json example 🤦♀️ .
Please see #232 for examples!
Solved in https://github.com/thruster-rs/Thruster/pull/232
Can this be closed?