mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
add helper converters into response
This commit is contained in:
@ -64,8 +64,8 @@ extern crate actix;
|
||||
extern crate actix_web;
|
||||
use actix_web::prelude::*;
|
||||
|
||||
fn index(req: HttpRequest) -> Result<HttpResponse> {
|
||||
Ok(httpcodes::HTTPOk.with_body("Hello world!"))
|
||||
fn index(req: HttpRequest) -> &'static str {
|
||||
"Hello world!"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -47,11 +47,11 @@ struct AppState {
|
||||
counter: Cell<usize>,
|
||||
}
|
||||
|
||||
fn index(req: HttpRequest<AppState>) -> HttpResponse {
|
||||
fn index(req: HttpRequest<AppState>) -> String {
|
||||
let count = req.state().counter.get() + 1; // <- get count
|
||||
req.state().counter.set(count); // <- store new count in state
|
||||
httpcodes::HTTPOk.with_body( // <- response with count
|
||||
format!("Num of requests: {}", count))
|
||||
|
||||
format!("Request number: {}", count) // <- response with count
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Reference in New Issue
Block a user