Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(volo-http): add docs for important modules #414

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Volo mainly consists of six crates:
1. The [`volo`][volo] crate, which contains the common components of the framework.
2. The [`volo-thrift`][volo-thrift] crate, which provides the Thrift RPC implementation.
3. The [`volo-grpc`][volo-grpc] crate, which provides the gRPC implementation.
4. The [`volo-build`][volo-build] crate, which generates thrift and protobuf code.
5. The [`volo-cli`][volo-cli] crate, which provides the CLI interface to bootstrap a new project and manages the idl files.
6. The [`volo-macros`][volo-macros] crate, which provides the macros for the framework.
4. The [`volo-http`][volo-http] crate, which provides the HTTP implementation.
5. The [`volo-build`][volo-build] crate, which generates thrift and protobuf code.
6. The [`volo-cli`][volo-cli] crate, which provides the CLI interface to bootstrap a new project and manages the idl files.
7. The [`volo-macros`][volo-macros] crate, which provides the macros for the framework.

### Features

Expand Down Expand Up @@ -66,9 +67,11 @@ For more information, you may refer to [our guide](https://www.cloudwego.io/zh/d

## Tutorial

Volo-Thrift: https://www.cloudwego.io/zh/docs/volo/volo-thrift/getting-started/
Volo-Thrift: <https://www.cloudwego.io/zh/docs/volo/volo-thrift/getting-started/>

Volo-gRPC: https://www.cloudwego.io/zh/docs/volo/volo-grpc/getting-started/
Volo-gRPC: <https://www.cloudwego.io/zh/docs/volo/volo-grpc/getting-started/>

Volo-HTTP: Work In Progess

## Examples

Expand Down Expand Up @@ -117,6 +120,7 @@ For the full list, you may refer to the [CREDITS.md](https://github.com/cloudweg
[volo]: https://docs.rs/volo
[volo-thrift]: https://docs.rs/volo-thrift
[volo-grpc]: https://docs.rs/volo-grpc
[volo-http]: https://docs.rs/volo-http
[volo-build]: https://docs.rs/volo-build
[volo-cli]: https://crates.io/crates/volo-cli
[volo-macros]: https://docs.rs/volo-macros
Expand Down
3 changes: 2 additions & 1 deletion volo-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-http"
version = "0.2.0-rc.4"
version = "0.2.0"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down Expand Up @@ -71,6 +71,7 @@ sonic-rs = { workspace = true, optional = true }

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
volo = { version = "0.10", path = "../volo" }

[features]
default = []
Expand Down
5 changes: 5 additions & 0 deletions volo-http/src/client/request_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(missing_docs)]

use std::error::Error;

use faststr::FastStr;
Expand Down Expand Up @@ -122,11 +124,13 @@ impl<'a, S> RequestBuilder<'a, S, Body> {
}

impl<'a, S, B> RequestBuilder<'a, S, B> {
/// Set method for the request.
pub fn method(mut self, method: Method) -> Self {
*self.request.method_mut() = method;
self
}

/// Get the reference of method in the request.
pub fn method_ref(&self) -> &Method {
self.request.method()
}
Expand Down Expand Up @@ -182,6 +186,7 @@ impl<'a, S, B> RequestBuilder<'a, S, B> {
Ok(self)
}

/// Set query for the uri in request from object with `Serialize`.
#[cfg(feature = "query")]
pub fn set_query<T>(mut self, query: &T) -> Result<Self>
where
Expand Down
5 changes: 5 additions & 0 deletions volo-http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![doc(
html_logo_url = "https://github.com/cloudwego/volo/raw/main/.github/assets/logo.png?sanitize=true"
)]
#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]

pub mod body;
#[cfg(feature = "client")]
pub mod client;
Expand Down
23 changes: 23 additions & 0 deletions volo-http/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ pub mod prelude {
pub use crate::cookie::CookieJar;
}

/// High level HTTP server.
///
/// # Examples
///
/// ```compile_fail
/// use std::net::SocketAddr;
///
/// use volo::net::Address;
/// use volo_http::server::{
/// route::{get, Router},
/// Server,
/// };
///
/// async fn index() -> &'static str {
/// "Hello, World!"
/// }
///
/// let app = Router::new().route("/", get(index));
/// let addr = "[::]:8080".parse::<SocketAddr>().unwrap();
/// let addr = Address::from(addr);
///
/// Server::new(app).run(addr).await.unwrap();
/// ```
pub struct Server<S, L> {
service: S,
layer: L,
Expand Down
Loading
Loading