actix_web_lab/web.rs
1//! Experimental services.
2//!
3//! Analogous to the `web` module in Actix Web.
4
5use std::borrow::Cow;
6
7#[allow(deprecated)]
8pub use crate::redirect::Redirect;
9#[cfg(feature = "spa")]
10pub use crate::spa::Spa;
11
12/// Create a relative or absolute redirect.
13///
14/// _This feature has [graduated to Actix Web][graduated]. Further development will occur there._
15///
16/// See [`Redirect`] docs for usage details.
17///
18/// # Examples
19/// ```
20/// use actix_web::App;
21/// use actix_web_lab::web as web_lab;
22///
23/// let app = App::new().service(web_lab::redirect("/one", "/two"));
24/// ```
25///
26/// [graduated]: https://docs.rs/actix-web/4/actix_web/web/struct.Redirect.html
27#[allow(deprecated)]
28#[deprecated(since = "0.19.0", note = "Type has graduated to Actix Web.")]
29pub fn redirect(from: impl Into<Cow<'static, str>>, to: impl Into<Cow<'static, str>>) -> Redirect {
30 Redirect::new(from, to)
31}
32
33/// Constructs a new Single-page Application (SPA) builder.
34///
35/// See [`Spa`] docs for more details.
36///
37/// # Examples
38/// ```
39/// # use actix_web::App;
40/// # use actix_web_lab::web::spa;
41/// let app = App::new()
42/// // ...api routes...
43/// .service(
44/// spa()
45/// .index_file("./examples/assets/spa.html")
46/// .static_resources_mount("/static")
47/// .static_resources_location("./examples/assets")
48/// .finish(),
49/// );
50/// ```
51#[cfg(feature = "spa")]
52pub fn spa() -> Spa {
53 Spa::default()
54}