thruster-rs / Thruster

A fast, middleware based, web framework written in Rust
MIT License
1.06k stars 47 forks source link

[FEATURE REQUEST] Add example for parse and validate a JSON body and query params #227

Closed Israel-Laguan closed 1 year ago

Israel-Laguan commented 1 year ago

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:

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?)

{
  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

trezm commented 1 year ago

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 🤦‍♀️ .

trezm commented 1 year ago

Please see #232 for examples!

Israel-Laguan commented 1 year ago

Solved in https://github.com/thruster-rs/Thruster/pull/232

Israel-Laguan commented 1 year ago

Can this be closed?