Nebula_Form
nebula_form
is a small Rust library that provides a simple interface for
working with form data.
Features
- Parse
application/x-www-form-urlencoded
and multipart/form-data
forms
from request bodies (currently only for warp
).
- A
Form
object that can be manipulated (fields added, removed, etc.)
- Create
application/x-www-form-urlencoded
and multipart/form-data
request
bodies from a Form
object.
Non-Features
- Multiple values for a single form field
- Note that there is no standard way to do this.
Usage
use nebula_form::{Form, Field};
use warp::Filter;
fn main() {
let form = Form::new();
form.insert("field-foo", Field::Text(String::from("contents")));
match form.get("field-foo") {
None => panic!("Field expected"),
Some(field) => {
match field {
Field::Text(txt) => println!(txt),
Field::File(_) => panic!("This should not be a file!"),
}
}
}
make_request("POST", form.to_url_encoded().as_bytes());
make_request("POST", form.to_multipart_bytes());
let hi = warp::path("some-form")
.and(warp::method::post())
.and(nebula_form::form_filter())
.map(|form: Form| {
format!("Hello {}!", form.get("name").unwrap())
});
}