1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

update actix web to stable version

This commit is contained in:
Rob Ede
2022-02-25 21:07:22 +00:00
parent c3a74c6823
commit 4dc9199781
61 changed files with 144 additions and 150 deletions

View File

@ -4,5 +4,5 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.3"
actix-web = "4"
serde = "1"

View File

@ -4,7 +4,7 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.3"
actix-web = "4"
failure = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -1,9 +1,11 @@
// This example is meant to show how to automatically generate a json error response when something goes wrong.
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io;
//! This example is meant to show how to automatically generate a json error response when something goes wrong.
use actix_web::http::StatusCode;
use actix_web::{web, App, HttpServer, ResponseError};
use std::{
fmt::{Display, Formatter, Result as FmtResult},
io,
};
use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer, ResponseError};
use serde::Serialize;
use serde_json::{json, to_string_pretty};
@ -21,13 +23,13 @@ impl Display for Error {
impl ResponseError for Error {
// builds the actual response to send back when an error occurs
fn error_response(&self) -> web::HttpResponse {
fn error_response(&self) -> HttpResponse {
let err_json = json!({ "error": self.msg });
web::HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
HttpResponse::build(StatusCode::from_u16(self.status).unwrap()).json(err_json)
}
}
async fn index() -> Result<web::HttpResponse, Error> {
async fn index() -> Result<HttpResponse, Error> {
Err(Error {
msg: "an example error message".to_string(),
status: 400,

View File

@ -4,8 +4,8 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = { version = "4.0.0-beta.21", features = ["openssl"] }
awc = "3.0.0-beta.19"
actix-web = "4"
awc = { version = "3.0.0-beta.19", features = ["openssl"] }
env_logger = "0.9"
futures = "0.3.1"

View File

@ -4,7 +4,7 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.3"
actix-web = "4"
futures = "0.3"
env_logger = "0.9.0"
serde = { version = "1.0", features = ["derive"] }

View File

@ -4,7 +4,7 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-beta.21"
actix-web = "4"
bytes = "1.1.0"
env_logger = "0.9.0"