Crates.io | rocket-response |
lib.rs | rocket-response |
version | 0.0.1-rc.2 |
source | src |
created_at | 2021-07-24 14:17:42.800358 |
updated_at | 2022-06-07 13:54:59.069548 |
description | Provides enum for variable Rocket Responses |
homepage | https://github.com/kolbma/rocket-response |
repository | https://github.com/kolbma/rocket-response |
max_upload_size | |
id | 426784 |
size | 24,310 |
This crate provides 3 enums to be flexible in returning Responses.
If you miss any Response, you are welcome to open an issue or even better provide a pull-request!
Because it is difficult to decide on the generics what might be useful, your usecases are really welcome in an issue.
For usage add the crate to your dependencies
[dependencies]
rocket-response = { version = "0.0.1-rc.2" }
You can depend on a couple of features, which provide additional types.
[dependencies]
rocket-response = { version = "0.0.1-rc.2", features = ["json", "templates-tera"] }
use rocket::{get, response::{self, status, Redirect}};
use rocket_response::RocketResponseGeneric2 as RocketResponse;
#[get("/<id>")]
pub(crate) fn rocket_response_generic2(
id: usize,
) -> RocketResponse<&'static str, Redirect> {
match id {
0 => RocketResponse::Flash(response::Flash::error(
Redirect::to("/"),
format!("Invalid id {}", id),
)),
1 => RocketResponse::Unauthorized(status::Unauthorized(Some(
"admin need authentication",
))),
_ => RocketResponse::Html(response::content::Html(
"<html><body>Hello world</body></html",
)),
}
}
You can choose between MIT License or Apache License 2.0.
Copyright (c) 2022 Markus Kolb
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 (including the next paragraph) 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.
Copyright 2022 Markus Kolb
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.