Crate xitca_http

Source
Expand description

Http module for Service trait oriented http handling.

This crate tries to serve both low overhead and ease of use purpose. All http protocols can be used separately with corresponding feature flag or work together for handling different protocols in one place.

§Examples

use std::convert::Infallible;

use xitca_http::{
    http::{IntoResponse, Request, RequestExt, Response},
    HttpServiceBuilder,
    RequestBody,
    ResponseBody
};
use xitca_service::{fn_service, Service, ServiceExt};

// xitca-http has to run inside a tcp/udp server.
xitca_server::Builder::new()
    // create http service with given name, socket address and service logic.
    .bind("xitca-http", "localhost:0",
        // a simple async function service produce hello world string as http response.
        fn_service(|req: Request<RequestExt<RequestBody>>| async {
            Ok::<Response<ResponseBody>, Infallible>(req.into_response("Hello,World!"))
        })
        // http service builder is a middleware take control of above function service
        // and bridge tcp/udp transport with the http service.
        .enclosed(HttpServiceBuilder::new())
    )?
    .build()

Re-exports§

pub use self::body::RequestBody;
pub use self::body::ResponseBody;
pub use self::error::BodyError;
pub use self::error::HttpServiceError;

Modules§

body
HTTP body types.
bytes
re-export bytes crate as module. re-export of bytes crate types.
config
Configuration for http service middlewares.
date
low resolution async date time for reduced syscall for generating http date time.
error
error types.
h1
http/1 specific module for types and protocol utilities.
http
re-export of http crate types.
util
utility module for useful middleware and service types.

Structs§

HttpServiceBuilder
HttpService middleware. bridge TCP/UDP traffic and HTTP protocols for Service type.
Request
Represents an HTTP request.
Response
Represents an HTTP response