Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kolbma/rocket-response
https://github.com/kolbma/rocket-response
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kolbma/rocket-response
- Owner: kolbma
- Created: 2021-07-24T14:06:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-03T22:54:27.000Z (over 1 year ago)
- Last Synced: 2024-10-15T04:16:09.800Z (about 1 month ago)
- Language: Rust
- Size: 78.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Rust](https://github.com/kolbma/rocket-response/actions/workflows/rust.yml/badge.svg)](https://github.com/kolbma/rocket-response/actions/workflows/rust.yml)
[![crates.io](https://img.shields.io/crates/v/rocket-response)](https://crates.io/crates/rocket-response)
[![docs](https://docs.rs/rocket-response/badge.svg)](https://docs.rs/rocket-response)# rocket-response - Provides enum for variable Rocket Responses
This [crate] provides 3 enums to be flexible in returning [Responses].
1. [RocketResponse] provides all non-generic [Response] types.
2. [RocketResponseGeneric] provides [Response]-types non-generic
and generic using a single generic type.
3. [RocketResponseGeneric2] allows a different [Flash] type.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].## Usage
For usage add the crate to your dependencies
```toml
[dependencies]
rocket-response = { version = "0.0.1-rc.2" }
```## Features
You can depend on a couple of features, which provide additional types.
* json
* msgpack
* templates-handlebars or templates-tera```toml
[dependencies]
rocket-response = { version = "0.0.1-rc.2", features = ["json", "templates-tera"] }
```## Example
```rust
use rocket::{get, response::{self, status, Redirect}};
use rocket_response::RocketResponseGeneric2 as RocketResponse;#[get("/")]
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(
"Hello world