File: actix-web.rs

package info (click to toggle)
rust-actix-http 3.9.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use actix_http::HttpService;
use actix_server::Server;
use actix_service::map_config;
use actix_web::{dev::AppConfig, get, App};

#[get("/")]
async fn index() -> &'static str {
    "Hello, world. From Actix Web!"
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> std::io::Result<()> {
    Server::build()
        .bind("hello-world", "127.0.0.1:8080", || {
            // construct actix-web app
            let app = App::new().service(index);

            HttpService::build()
                // pass the app to service builder
                // map_config is used to map App's configuration to ServiceBuilder
                // h1 will configure server to only use HTTP/1.1
                .h1(map_config(app, |_| AppConfig::default()))
                .tcp()
        })?
        .run()
        .await
}