mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
normalize ports to 8080
This commit is contained in:
@ -5,4 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
|
||||
env_logger = "0.9"
|
||||
log = "0.4"
|
||||
serde = "1"
|
||||
|
@ -11,7 +11,7 @@ representation of the error.
|
||||
```shell
|
||||
cd json/json_decode_error
|
||||
cargo run
|
||||
# Started HTTP server: 127.0.0.1:8088
|
||||
# Started HTTP server: 127.0.0.1:8080
|
||||
```
|
||||
|
||||
## Examples
|
||||
@ -23,7 +23,7 @@ ellipsis `...`.
|
||||
- A well-formed request
|
||||
|
||||
```shell
|
||||
$ curl -i 127.0.0.1:8088 -H 'Content-Type: application/json' -d '{"name": "Alice"}'
|
||||
$ curl -i 127.0.0.1:8080 -H 'Content-Type: application/json' -d '{"name": "Alice"}'
|
||||
HTTP/1.1 200 OK
|
||||
...
|
||||
|
||||
@ -33,7 +33,7 @@ ellipsis `...`.
|
||||
- Missing `Content-Type` header
|
||||
|
||||
```shell
|
||||
$ curl -i 127.0.0.1:8088 -d '{"name": "Bob"}'
|
||||
$ curl -i 127.0.0.1:8080 -d '{"name": "Bob"}'
|
||||
HTTP/1.1 415 Unsupported Media Type
|
||||
...
|
||||
|
||||
@ -43,7 +43,7 @@ ellipsis `...`.
|
||||
- Malformed JSON
|
||||
|
||||
```shell
|
||||
$ curl -i 127.0.0.1:8088 -H 'Content-Type: application/json' -d '{"name": "Eve}'
|
||||
$ curl -i 127.0.0.1:8080 -H 'Content-Type: application/json' -d '{"name": "Eve}'
|
||||
HTTP/1.1 400 Bad Request
|
||||
...
|
||||
|
||||
@ -53,7 +53,7 @@ ellipsis `...`.
|
||||
- JSON value of wrong type
|
||||
|
||||
```shell
|
||||
$ curl -i 127.0.0.1:8088 -H 'Content-Type: application/json' -d '{"name": 350}'
|
||||
$ curl -i 127.0.0.1:8080 -H 'Content-Type: application/json' -d '{"name": 350}'
|
||||
HTTP/1.1 422 Unprocessable Entity
|
||||
...
|
||||
|
||||
@ -63,7 +63,7 @@ ellipsis `...`.
|
||||
- Wrong JSON key
|
||||
|
||||
```shell
|
||||
$ curl -i 127.0.0.1:8088 -H 'Content-Type: application/json' -d '{"namn": "John"}'
|
||||
$ curl -i 127.0.0.1:8080 -H 'Content-Type: application/json' -d '{"namn": "John"}'
|
||||
HTTP/1.1 422 Unprocessable Entity
|
||||
...
|
||||
|
||||
|
@ -27,6 +27,10 @@ fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new().service(greet).app_data(
|
||||
web::JsonConfig::default()
|
||||
@ -34,7 +38,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.error_handler(json_error_handler),
|
||||
)
|
||||
})
|
||||
.bind("127.0.0.1:8088")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -5,5 +5,8 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
|
||||
env_logger = "0.9"
|
||||
log = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -38,12 +38,12 @@ async fn index() -> Result<HttpResponse, Error> {
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let ip_address = "127.0.0.1:8000";
|
||||
println!("Running server on {}", ip_address);
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(|| App::new().service(web::resource("/").route(web::get().to(index))))
|
||||
.bind(ip_address)
|
||||
.expect("Can not bind to port 8000")
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ edition = "2021"
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
|
||||
env_logger = "0.9.0"
|
||||
env_logger = "0.9"
|
||||
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||
json = "0.12"
|
||||
log = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -58,8 +58,9 @@ async fn index_mjsonrust(body: web::Bytes) -> Result<HttpResponse, Error> {
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
env_logger::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
|
Reference in New Issue
Block a user