mirror of
https://github.com/actix/actix-web.git
synced 2025-02-19 12:35:31 +00:00
Add other endpoints to actix web example
This commit is contained in:
parent
42bd5eebdb
commit
a94b5b89a5
1 changed files with 15 additions and 1 deletions
|
@ -1,19 +1,33 @@
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use actix_http::HttpService;
|
use actix_http::HttpService;
|
||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use actix_service::map_config;
|
use actix_service::map_config;
|
||||||
use actix_web::{dev::AppConfig, get, App};
|
use actix_web::{dev::AppConfig, get, App};
|
||||||
|
|
||||||
|
static LARGE: OnceLock<String> = OnceLock::new();
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn index() -> &'static str {
|
async fn index() -> &'static str {
|
||||||
"Hello, world. From Actix Web!"
|
"Hello, world. From Actix Web!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/large")]
|
||||||
|
async fn large() -> &'static str {
|
||||||
|
LARGE.get_or_init(|| "123456890".repeat(1024 * 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/medium")]
|
||||||
|
async fn medium() -> &'static str {
|
||||||
|
LARGE.get_or_init(|| "123456890".repeat(1024 * 5))
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
Server::build()
|
Server::build()
|
||||||
.bind("hello-world", "127.0.0.1:8080", || {
|
.bind("hello-world", "127.0.0.1:8080", || {
|
||||||
// construct actix-web app
|
// construct actix-web app
|
||||||
let app = App::new().service(index);
|
let app = App::new().service(index).service(large).service(medium);
|
||||||
|
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
// pass the app to service builder
|
// pass the app to service builder
|
||||||
|
|
Loading…
Reference in a new issue