Participate in Web Framework Benchmarks by TechEmpower
Closed this issue · 26 comments
I would prefer to publish Rustful on crates.io first, to make it easier to prevent surprising breaks, but you or anyone else are still welcome to add a benchmark before that. You have my blessing :)
I should add that I will almost certainly not have the time to maintain external benchmarks, like this one, so it's up to the implementor and anyone interested to keep them up to date.
Thanks a lot. I might stumble here to ask you a few things though. Not the best rust developer so far, but I'm trying and enjoying it! :)
No problem, you can ask as much as you want. It would be nice if you could add a link in your first post to the implementation, just for reference.
Sure will
I've started implementing this feature here
Nice! It will be interesting to see where this leads.
I'm closing this because of lack of activity. It can be reopened again if anyone happens to be interested in implementing those benchmarks.
I've finally found some time to give it a try:
Need little help with json serialization and also I wonder if it's possible to add Content-Type
information on a route basis, rather than on the Server
.
https://github.com/whiplash/FrameworkBenchmarks/blob/master/frameworks/Rust/rustful/src/main.rs
Nice! You can access and change the response headers through the response. What do you need help with, regarding JSON serialization?
Well as you can see here in the json function
I would like to return {"message":"Hello, World!"}
, hence I wrote the little struct
, but I still get just the string.
That doesn't sound right. I wonder if it "optimizes" it to leave out the field name, since it's only one field. Have you tried to add an other field to see what happens?
Oh, wait! You have conflicting paths, so you have overwritten the JSON handler with the plain text handler. ":name" is a path variable that takes a value in its place, but you can't have two parallel variables, because there is no way to see the difference between them.
I just figured that out as well
Yeah, it would be really strange if the serialisation would leave out field names.
Weird though... shouldn't it pattern-match
on the the :name string?
What do you mean? How?
Nevermind (I don't even know if it's feasible in Rust, to say the truth).
How do I then accomplish that kind of thing?
/json
=> j
function
/plaintext
=> p
function
Leave out the :
. That's the variable indicator. Like this. You can also write /
in front of them, like in your example. Here are more examples that may be better.
Great. That was easy.
I'll now figure out how to add the Content-Type thing and try to push it over.
Should I go with a response.headers_mut().set
kind of thing?
Thank you so much.
Yes, that's the way it's done. You may also want to store &'static str
instead of String
as your message to avoid cloning and allocating more than necessary.
Ok. Fixed it all a little.
Having &static str
gives me issue with RustcDecodable
.
Check it out, and let me know if I forgot anything.
The only things I can see is that you are formatting the plain text string (Response
takes string slices as well) and that you could use .into()
instead of .to_string()
to avoid firing up the formatting machinery. Not that I think the impact is that big, but still.
I just wish that we could skip the HandlerFn
stuff, but the compiler is still buggy there (last time I checked).
Great. Yeah I also wish I could get rid of the (unused) Context
parameter.
Alright.
Thanks again!
Will keep you posted.
Just rename the argument to _context
or _
or something. The underscore will tell the compiler to ignore it.
Just to clarify: you should be able to change response.send(format!("Hello, World!"));
to response.send("Hello, World!");