131 stable releases

Uses new Rust 2021

2.0.2 Jun 28, 2022
2.0.0 May 30, 2022
1.3.30 May 15, 2022
1.3.19 Mar 30, 2022
0.9.0 Oct 8, 2021

#29 in Network programming

Download history 1115/week @ 2022-03-15 941/week @ 2022-03-22 952/week @ 2022-03-29 887/week @ 2022-04-05 1261/week @ 2022-04-12 834/week @ 2022-04-19 2345/week @ 2022-04-26 1744/week @ 2022-05-03 3159/week @ 2022-05-10 1864/week @ 2022-05-17 1399/week @ 2022-05-24 2698/week @ 2022-05-31 1039/week @ 2022-06-07 787/week @ 2022-06-14 989/week @ 2022-06-21 3089/week @ 2022-06-28

6,236 downloads per month
Used in 5 crates


23K SLoC

Poem OpenAPI

Fast and Type-Safe OpenAPI implementation for Poem.

Poem-openapi allows you to easily implement APIs that comply with the OpenAPIv3 specification. It uses procedural macros to generate a lots of boilerplate code, so that you only need to focus on the more important business implementations.


  • Type safety If your codes can be compiled, then it is fully compliant with the OpenAPI v3 specification.
  • Rustfmt friendly Do not create any DSL that does not conform to Rust's syntax specifications.
  • IDE friendly Any code generated by the procedural macro will not be used directly.
  • Minimal overhead All generated code is necessary, and there is almost no overhead.

Crate features

To avoid compiling unused dependencies, Poem gates certain features, some of which are disabled by default:

Feature Description
chrono Integrate with the chrono crate.
humantime Integrate with the humantime crate
swagger-ui Add swagger UI support
rapidoc Add RapiDoc UI support
redoc Add Redoc UI support
email Support for email address string
hostname Support for hostname string
uuid Integrate with the uuid crate
url Integrate with the url crate
bson Integrate with the bson crate
rust_decimal Integrate with the rust_decimal crate
static-files Support for static file response


This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.


use poem::{listener::TcpListener, Route};
use poem_openapi::{param::Query, payload::PlainText, OpenApi, OpenApiService};

struct Api;

impl Api {
    #[oai(path = "/hello", method = "get")]
    async fn index(&self, name: Query<Option<String>>) -> PlainText<String> {
        match name.0 {
            Some(name) => PlainText(format!("hello, {}!", name)),
            None => PlainText("hello!".to_string()),

async fn main() -> Result<(), std::io::Error> {
    let api_service =
        OpenApiService::new(Api, "Hello World", "1.0").server("http://localhost:3000/api");
    let ui = api_service.swagger_ui();
    let app = Route::new().nest("/api", api_service).nest("/", ui);


This feature needs to be opted-in. It can be done by adding the feature in Cargo.toml file

poem = "1"
poem-openapi = { version = "2", features = ["swagger-ui"]}
tokio = { version = "1", features = ["full"] }

Run example

Open http://localhost:3000/ in your browser, you will see the Swagger UI that contains these API definitions.

> cargo run --example hello_world

> curl http://localhost:3000

> curl http://localhost:3000\?name\=sunli
hello, sunli!        


The minimum supported Rust version for this crate is 1.57.0.


🎈 Thanks for your help improving the project! We are so happy to have you!


Licensed under either of


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Poem by you, shall be licensed as Apache, without any additional terms or conditions.


~475K SLoC