4 releases (major breaking)

3.0.0 Jan 9, 2024
2.0.0 Nov 28, 2023
1.0.0 Oct 7, 2023
0.1.0 Aug 7, 2023

#1156 in Web programming

Download history 1304/week @ 2024-01-06 1537/week @ 2024-01-13 1239/week @ 2024-01-20 1530/week @ 2024-01-27 1574/week @ 2024-02-03 1144/week @ 2024-02-10 917/week @ 2024-02-17 1680/week @ 2024-02-24 1653/week @ 2024-03-02 1789/week @ 2024-03-09 1930/week @ 2024-03-16 1397/week @ 2024-03-23 1855/week @ 2024-03-30 1835/week @ 2024-04-06 2181/week @ 2024-04-13 2530/week @ 2024-04-20

8,516 downloads per month
Used in 14 crates (11 directly)

MIT/Apache

305KB
4.5K 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 = "3"

Enable actix-web integration with RapiDoc.

[dependencies]
utoipa-rapidoc = { version = "3", 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.

Overiding 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("/rapidoc", ApiDoc::openapi()));

Serve RapiDoc via rocket framework.

use utoipa_rapidoc::RapiDoc;

rocket::build()
    .mount(
        "/",
        RapiDoc::with_openapi("/rapidoc", ApiDoc::openapi()),
    );

Serve RapiDoc via axum framework.

use axum::Router;
use utoipa_rapidoc::RapiDoc;
let app = Router::<S>::new()
    .merge(RapiDoc::with_openapi("/rapidoc", ApiDoc::openapi()));

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–39MB
~568K SLoC