#rocket-web #rocket #web #macro #utility-macro #utility #handler

macro rocket_modules

A small crate that adds macros to conveniently organize Rocket route handlers in modules

3 releases

0.1.2 Nov 24, 2023
0.1.1 Jul 24, 2022
0.1.0 Jul 24, 2022

#613 in HTTP server

Download history 9/week @ 2024-02-21 60/week @ 2024-02-28 8/week @ 2024-03-06 3/week @ 2024-03-13

80 downloads per month

MIT/Apache

11KB
68 lines

Rocket Modules

Build Status Publish Status Language: Rust Crates.io Version

A small crate that adds macros to conveniently organize Rocket route handlers in modules. This crate is not directly associated with the rocket project, although it is built upon it.

Example

Instead of explicitly stating all routes that should be mounted...

#[get("/")]
pub fn all_articles() {}

#[get("/<_id>")]
pub fn get_article(_id: &str) {}

#[post("/<_id>")]
pub fn post_article(_id: &str) {}

#[route(PATCH, uri = "/<_id>")]
pub fn patch_article(_id: &str) {}

#[launch]
fn rocket() -> _ {
    rocket::build()
      .mount("/articles", routes![all_articles, get_article, post_article, patch_article])
}

...this crate allows you to write the following:

#[route_module]
mod articles {
  // Same code as above
  ...
}

#[launch]
fn rocket() -> _ {
    rocket::build()
      .mount("/articles", module!(articles))
}

Installation

To install rocket_modules, add it to your dependencies in your Cargo.toml.

You should also add a dependency to rocket (version 0.5.0 or higher) if not already present:

[dependencies]
rocket = "0.5.0"
rocket_modules = "0.1.2"

Note: Compatability of this crate was tested with Rocket version "0.5.0", it may or may not work with previous versions.

License

This code is dual-licensed and availabe under MIT-License or Apache 2.0-License depending on what suits your needs best.

Apache 2.0

Copyright 2022 Antonius Naumann

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

MIT

MIT License

Copyright (c) 2022 Antonius Naumann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Dependencies

~15–51MB
~818K SLoC