A simple http server?

I'm looking to benchmark something in Rust, comparing it to Go. The Go implementation just uses the standard library for creating a basic http server that servers from json(fetched from a database).

I'd like to do something similar in Rust and compare performance.

Are there any simple implementations of http servers out there?

I need a basic functionality, i.e. make an endpoint(say /users/get) that returns JSON parsed from a Vec<RustStruct>.

Any good recommendations? I'd rather not fire up a whole big framework for it :smiley:

This isn't quite what you're asking for, but I like warp for something like this. It's indeed a framework, but may reduce the amount of code you'd have to work relative to something lower level.

My first thought was microserver?

Seed uses this in their makefile for running a dev server, and it is geared to that use case. It probably isn't what you want exactly (it's an application you'd run after cargo install)

But then I managed to find http-test-server which looks more like what you asked for

tiny_http is a good small server library.

See also rouille, a minimal “framework” built on top of tiny_http.

1 Like

If I understand correctly if one makes an HTTP server in Go it's going to be using Go's "green threads" or "coroutines" or whatever they are called, to handle many connections at the same time.

As such to make a valid comparison to a Rust HTTP server one would have to use Rusts equivalent, that is async "tasks".

So perhaps Actix is the way to go. Perhaps there are others I don't know of yet.

I would not worry about firing up a whole big frame work, provided one can write the HTTP server functionality one wants in a page or two of code. As one can with actix-web: https://actix.rs/

Surprised I haven't seen the most popular choice being mentioned yet: hyper

Hyper is the low-level option, and I guess people usually use higher-level options.

Here are some examples of Rust, Go, and Haskell webservers. Some binary size and rough perf data is also included.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.