10 releases (5 major breaking)

5.0.0 Oct 14, 2024
4.0.1-rc.0 Oct 2, 2024
4.0.1-beta.0 Sep 1, 2024
4.0.1-alpha.0 May 30, 2024
0.1.0 Aug 7, 2023

#1405 in Web programming

Download history 2077/week @ 2024-07-18 2669/week @ 2024-07-25 3231/week @ 2024-08-01 3415/week @ 2024-08-08 3011/week @ 2024-08-15 3960/week @ 2024-08-22 4160/week @ 2024-08-29 3691/week @ 2024-09-05 3912/week @ 2024-09-12 5374/week @ 2024-09-19 7040/week @ 2024-09-26 6255/week @ 2024-10-03 8528/week @ 2024-10-10 8217/week @ 2024-10-17 11115/week @ 2024-10-24 12433/week @ 2024-10-31

40,946 downloads per month
Used in 19 crates (14 directly)

MIT/Apache

400KB
6K SLoC

utoipa-rapidoc

This crate works as a bridge between utoipa and RapiDoc OpenAPI visualizer.

Utoipa build crates.io docs.rs rustc

Utoipa-rapidoc provides simple mechanism to transform OpenAPI spec resource to a servable HTML file which can be served via predefined framework integration or used standalone and served manually.

You may find fullsize examples from utoipa's Github repository.

Crate Features

  • actix-web Allows serving RapiDoc via actix-web. version >= 4
  • rocket Allows serving RapiDoc via rocket. version >=0.5
  • axum Allows serving RapiDoc via axum. version >=0.7

Install

Use RapiDoc only without any boiler plate implementation.

[dependencies]
utoipa-rapidoc = "5"

Enable actix-web integration with RapiDoc.

[dependencies]
utoipa-rapidoc = { version = "5", features = ["actix-web"] }

Using standalone

Utoipa-rapidoc can be used standalone as simply as creating a new RapiDoc instance and then serving it by what ever means available as text/html from http handler in your favourite web framework.

RapiDoc::to_html method can be used to convert the RapiDoc instance to a servable html file.

let rapidoc = RapiDoc::new("/api-docs/openapi.json");

// Then somewhere in your application that handles http operation.
// Make sure you return correct content type `text/html`.
let rapidoc_handler = move || {
    rapidoc.to_html()
};

Customization

Utoipa-rapidoc can be customized and configured only via RapiDoc::custom_html method. This method empowers users to use a custom HTML template to modify the looks of the RapiDoc UI.

The template should contain $specUrl variable which will be replaced with user defined OpenAPI spec url provided with RapiDoc::new function when creating a new RapiDoc instance. Variable will be replaced during RapiDoc::to_html function execution.

Overriding the HTML template with a custom one.

let html = "...";
RapiDoc::new("/api-docs/openapi.json").custom_html(html);

Examples

Serve RapiDoc via actix-web framework.

use actix_web::App;
use utoipa_rapidoc::RapiDoc;

App::new()
    .service(
        RapiDoc::with_openapi("/api-docs/openapi.json", ApiDoc::openapi()).path("/rapidoc")
    );

Serve RapiDoc via rocket framework.

use utoipa_rapidoc::RapiDoc;

rocket::build()
    .mount(
        "/",
        RapiDoc::with_openapi("/api-docs/openapi.json", ApiDoc::openapi()).path("/rapidoc"),
    );

Serve RapiDoc via axum framework.

use axum::Router;
use utoipa_rapidoc::RapiDoc;

let app = Router::<S>::new()
    .merge(
        RapiDoc::with_openapi("/api-docs/openapi.json", ApiDoc::openapi()).path("/rapidoc")
    );

License

Licensed under either of Apache 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be dual licensed, without any additional terms or conditions.

Dependencies

~1–34MB
~539K SLoC