thruster-rs / Thruster

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

feat: add json and set_status methods for basic context #185

Closed saiumesh535 closed 3 years ago

saiumesh535 commented 3 years ago

Added json and set_status methods in BasicContext. This is similar to one in express as

res.json(...)
trezm commented 3 years ago

Code looks great -- what do you think about...

Just a thought, feel free to push back. Seems like it would be nice though to be able to just pass context.json(MySerializableStruct {}) though!

saiumesh535 commented 3 years ago

Code looks great -- what do you think about...

* Requiring the argument to be `Serialize` from serde rather than just a string

* Calling `https://docs.serde.rs/serde_json/ser/fn.to_vec.html` to prevent struct -> string -> vec and just going struct -> vec

* Putting this behind a feature flag so we don't always require serde/serde_json

Just a thought, feel free to push back. Seems like it would be nice though to be able to just pass context.json(MySerializableStruct {}) though!

Hey. I think it's a good ides and I added now. let me know if I'm missing something. Thanks

trezm commented 3 years ago

Perfect! I didn't realize that the serde packages weren't optional already, so that's another thing for me to do later. Great addition though!!