How to create hello world web service using Tokio?

I'm completely new to Rust and trying to create a minimal web service using Tokio to answer a request GET / with "hello world".

I had a look at the Hello Tokio example in the Tokio dokumentation. But it did not help me much. I have no idea about Redis.

Could somebody please point me to some resources to create a minimal web service with Rust and Tokio. Thanks in advance.

Have you ever created a simple server before? In some other language perhaps?
(I mean I can give you the code right away, but I think it'd be more useful for you going this way)

1 Like

Tokio is just an asynchronous runtime; to respond to HTTP requests you would have to implement your own code for Tokio to run. You can do this, but there are already existing server frameworks that run under Tokio. Have you considered Warp, for example? It has a pretty simple "Hello World" example in its README that might suit your needs.

1 Like

I have a Java background and I know how to do it with servlets or Spring. I know the HTTP basics and now I'm looking for something like servlets in Rust. :grinning:

Maybe Tokio is not the way to go. It is just the framework I heard about first. As I said I'm a beginner. Please feel free to suggest something else.

I have no idea about Warp. But I'll have a look at it. Thanks for your suggestion!

1 Like

At this point I am going to ask what you want to build.
If you want a framework, you need to look at something like Warp (fairly minimal), Actix Web or Rocket (more features). Tokio in itself is not super useful since it is an "async runtime" and is not directly used. In fact, there are other runtimes as well (async-std being a prime example).
Also, I don't think there are full blown Spring like frameworks in Rust yet. You have to use a bunch of crates to give the parts, such as an ORM, authentication manager, templates etc.

1 Like

I think, that I will go with Warp for now. It has the right abstraction level for my current level of knowledge.

1 Like

For now, Warp fits my needs. As I'm just getting started with web services in Rust, a Spring like framework would be overwhelming for me.

1 Like

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.