mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 23:07:01 +00:00
Support File up/download
This commit is contained in:
parent
25117a035f
commit
d030fa539f
10 changed files with 659 additions and 110 deletions
18
README.md
18
README.md
|
@ -22,7 +22,6 @@ gotham_restful = "0.0.1"
|
|||
A basic server with only one resource, handling a simple `GET` request, could look like this:
|
||||
|
||||
```rust
|
||||
#
|
||||
/// Our RESTful Resource.
|
||||
#[derive(Resource)]
|
||||
#[rest_resource(read_all)]
|
||||
|
@ -54,6 +53,23 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
Uploads and Downloads can also be handled, but you need to specify the mime type manually:
|
||||
|
||||
```rust
|
||||
#[derive(Resource)]
|
||||
#[rest_resource(create)]
|
||||
struct ImageResource;
|
||||
|
||||
#[derive(FromBody, RequestBody)]
|
||||
#[supported_types(mime::IMAGE_GIF, mime::IMAGE_JPEG, mime::IMAGE_PNG)]
|
||||
struct RawImage(Vec<u8>);
|
||||
|
||||
#[rest_create(ImageResource)]
|
||||
fn create(_state : &mut State, body : RawImage) -> Raw<Vec<u8>> {
|
||||
Raw::new(body.0, mime::APPLICATION_OCTET_STREAM)
|
||||
}
|
||||
```
|
||||
|
||||
Look at the [example] for more methods and usage with the `openapi` feature.
|
||||
|
||||
## License
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue