autortr-rocket
autortr-rocket is a lightweight Rust library designed for automatic route mapping in web applications
for the Rocket framework.. It simplifies the process of defining and managing HTTP routes by automatically
registering functions annotated with custom attributes like #[request_mapping]
Or #[get_mapping], #[post_mapping], #[patch_mapping], #[put_mapping],#[delete_mapping] and #[head_mapping].
1.Usage
Add this to your Cargo.toml:
[]
= "0.2"
# And
# If necessary
= "${version}"
= "${version}"
= "${version}"
2.APIs
2.0.Macros
#[request_mapping]namespacemethodGETPOSTPUTPATCHDELETEHEAD
pathdata<form>- …
get_mappingdefault#[get_mapping("${path}")]
namespacepathdata<form>
post_mapping- Same as above(
get_mapping)
- Same as above(
put_mapping- Same as above(
get_mapping)
- Same as above(
patch_mapping- Same as above(
get_mapping)
- Same as above(
delete_mapping- Same as above(
get_mapping)
- Same as above(
head_mapping- Same as above(
get_mapping)
- Same as above(
2.1.Import
use *;
2.2.Controller
API functions.
2.2.1.GET
// Default mount base-path is: "/"
app.mount;
// GET: method == get; path == "/get"
// -> rocket: #[get("/get")]
// -> HTTP: http://127.0.0.1:8000/get
2.2.2.POST
// POST: method == post; path == "/post"
// -> rocket: #[post("/post")]
// -> HTTP: http://127.0.0.1:8000/post
2.2.3.PUT
// PUT: method == put; path == "/put"
// -> rocket: #[put("/put")]
// -> HTTP: http://127.0.0.1:8000/put
2.2.4.PATCH
// PATCH: method == patch; path == "/patch"
// -> rocket: #[patch("/patch")]
// -> HTTP: http://127.0.0.1:8000/patch
2.2.5.DELETE
// DELETE: method == delete; path == "/delete"
// -> rocket: #[delete("/delete")]
// -> HTTP: http://127.0.0.1:8000/delete
2.2.5.Namespace
Custom mount base-path by namespace attribute.
Rocket'sbase
app.mount;
// GET: namespace == rocket, method == get; path == "/namespace"
// -> rocket: #[get("/namespace")]
// -> rocket: mount: /rocket/namespace
// -> HTTP: http://127.0.0.1:8000/rocket/namespace
2.3.App instance
// ----------------------------------------------------------------
// 1.Populate Rocket instance.
// -> auto-mount by Autortr
let rocket_app = app; // Rocket<Build>
// 2.Configure
// rocket_app.[...]
// 3.Launch
// let _ = app.attach(configure())[.xxx.yyy.zzz].launch().await?;
let _ = rocket_app.attach.launch.await?;
Ok
2.3.1.launch
2.3.2.main
async
2.4.Next
2.4.1.Other's macros
-
get_mapping#[request_mapping(method="get")]
-
post_mapping#[request_mapping(method="post")]
-
put_mapping#[request_mapping(method="put")]
-
patch_mapping#[request_mapping(method="patch")]
-
delete_mapping#[request_mapping(method="delete")]
-
head_mapping- Supported or not?
2.4.2.Other's web framework
- …