Crates.io | simbld-http |
lib.rs | simbld-http |
version | 0.2.1 |
source | src |
created_at | 2024-11-21 12:42:57.728076 |
updated_at | 2024-11-25 04:23:49.186064 |
description | A comprehensive HTTP response library for Rust. |
homepage | |
repository | https://github.com/simbld/simbld-http |
max_upload_size | |
id | 1456087 |
size | 129,020 |
ok_with_cookie
: Generate an OK response with an attached cookie.
bad_request_with_cookie
: Generate a Bad Request response with an attached cookie.
ok_with_headers
: Generate an OK response with custom headers.
bad_request_with_headers
: Generate a Bad Request response with custom headers.
x-status-description
: A description associated with the HTTP status code.
x-response-time-ms
: The request processing time in milliseconds.
Complete examples, including detailed use cases and advanced integrations, are available in the project's GitHub repository (https://github.com/simbld/simbld-http/tree/main/examples).
Basic Usage: An introduction to using simbld-http.
Middleware Integration: Demonstration of integration into an Actix Web server with custom middleware.
Response Helpers: Using helpers to create responses with cookies or custom headers.
Simbld-HTTP
is a modular and comprehensive Rust library designed for managing HTTP response codes. Whether you're building APIs, handling custom response codes, or integrating middleware, Simbld-HTTP provides an organized and extensible framework to simplify your workflow.
Support for Standard and Custom HTTP Codes:
Handles all standard HTTP response families: 1xx to 5xx. Extends with custom families: 6xx, 7xx, and 9xx. Includes detailed descriptions for every status code.
Extensive Utilities:
JSON and XML response formatting. Helpers for paginated and generic HTTP responses. Middleware integration for Actix Web.
Easy Extensibility:
Add new families or custom helpers with minimal effort.
Developer-Friendly: Intuitive API with detailed documentation. Modular Design: Use only the parts you need for your project. Future-Proof: Easily extend to accommodate evolving HTTP standards and custom needs. Battle-Tested: Includes robust tests to ensure reliability.
Add Simbld-HTTP to your ``Cargo.toml
:
[dependencies]
simbld-http = "0.2.0"
Run the following command to generate and open the documentation:
cargo doc --no-deps --open
The full documentation will be available on docs.rs after publishing. Stay tuned for updates!
use simbld_http::responses::ResponsesTypes;
let response = ResponsesTypes::Success(ResponsesSuccessCodes::Ok);
println!("Code: {}, Description: {}", response.to_u16(), response.description());
use simbld_http::responses::ResponsesCrawlerCodes;
use strum::EnumProperty;
fn main() {
let code = ResponsesCrawlerCodes::ParsingErrorHeader;
println!(
"Code: {}, Description: {}",
code.to_u16(),
code.get_str("Description").unwrap()
);
}
cargo run --example usage
cargo run --example middleware_usage
curl -i http://127.0.0.1:8080/
Family | Description |
---|---|
1xx | Informational responses (e.g., Continue , Processing ) |
2xx | Successful responses (e.g., OK , Created ) |
3xx | Redirection responses (e.g., Moved Permanently , Temporary Redirect ) |
4xx | Client errors (e.g., Bad Request , Unauthorized ) |
5xx | Server errors (e.g., Internal Server Error , Service Unavailable ) |
6xx | Service operations (e.g., Service Timeout ) |
7xx | Crawler responses (e.g., Rate Limited , Crawl Blocked ) |
9xx | Local API errors (e.g., InsufficientFunds , ExpiredCard ) |
We welcome contributions to Simbld-HTTP! Help us make this library the go-to solution for HTTP response code management in Rust.
1
Fork this repository2
Clone your forkgit clone git@github.com:<your-username>/simbld-http.git
3
Create a branch for your changesgit switch -c feature/<your-feature-name>
4
Test your changescargo test
5
Open a pull requestThis project is licensed under the MIT License. See the LICENSE file for details.