pub struct HttpServer {
    pub routes: Routes,
    // some fields omitted
}
Expand description

HTTP Server

This struct stores the listener, which listens for incoming connections and handles them

Example:

let http_server = HttpServer::new("127.0.0.1", "8080").await.unwrap(); // Create a new http listener

Fields

routes: Routes

Implementations

New

Create a new server, with a given IP and port

Example

let http_server = HttpServer::new("127.0.0.1", "8080").await.unwrap();
New TLS

Create a new server, with a given IP and port, and a TLS certificate and key

Example

let http_server = HttpServer::new_tls("127.0.0.1", "8080", "cert.pem", "key.pem").await.unwrap();
Note

The certificate and key files must be in PEM and KEY formats respectively. The key must not be encrypted.

Listen

Listen for new connections.

Run handle_connection upon connection.

Note

If you are using TLS, this function will not return until the server is shut down.

All errors will be printed to the console, instead of panicking.

Set Read Buffer Size

Set the read buffer size for the server. The default value is 8192 bytes.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.