diff options
author | Martin Fischer <martin@push-f.com> | 2021-04-09 12:32:01 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-04-09 12:49:02 +0200 |
commit | 9df4a6c0b55b2e680eca4e89489ad4c684bfb127 (patch) | |
tree | 9d95f03bd52509bb29b76ad9ed21f3d796272619 /README.md | |
parent | bfeddf5d15ddaa9937ceeba04678ad6c4a4e8aea (diff) |
make hyper dependency optional
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -1,19 +1,25 @@ # Sputnik -A microframework based on [Hyper](https://hyper.rs/) providing traits to: +This library extends the types from the [http](https://crates.io/crates/http) crate: -* extend `http::request::Parts` with query parameter deserialization & cookie parsing -* extend `hyper::Body` with form deserialization (and JSON deserialization with the `json` feature) -* extend `http::response::Builder` with methods to set & delete cookies and set the Content-Type +* extends `http::request::Parts` with query parameter deserialization & cookie parsing +* extends `http::response::Builder` with methods to set cookies and content-types + +If you use [Hyper](https://hyper.rs/) and want to deserialize request bodies +with [Serde](https://serde.rs/) you can enable the following feature flags: + +- `hyper_body` provides a trait to extend `hyper::Body` with an + `into_form` method for parsing data submitted from HTML forms. +- `hyper_body_json` additionaly provides an `into_json` method Furthermore Sputnik provides what's necessary to implement [signed & expiring cookies](#signed--expiring-cookies) with the expiry date encoded into the signed cookie value, providing a more lightweight alternative to JWT if you don't need interoperability. -Sputnik does **not** handle routing. For most web applications `match`ing on -(method, path) suffices. If you need path variables, you can use one of the -many [router crates](https://crates.io/keywords/router). +Sputnik does **not** handle routing because even complex routing can be quite +easily implemented with nested `match` blocks. If you want a more high-level +router, you can check out the [router crates](https://crates.io/keywords/router). Sputnik encourages you to create your own error enum and implement `From` conversions for every error type, which you want to short-circuit with the `?` @@ -35,8 +41,8 @@ use hyper::{Method, Server, StatusCode, Body}; use hyper::http::request::Parts; use hyper::http::response::Builder; use serde::Deserialize; -use sputnik::{mime, request::{SputnikParts, SputnikBody}, response::SputnikBuilder}; -use sputnik::request::FormError; +use sputnik::{mime, request::SputnikParts, response::SputnikBuilder}; +use sputnik::hyper_body::{SputnikBody, FormError}; type Response = hyper::Response<Body>; |