Created
February 25, 2020 13:24
-
-
Save wafflespeanut/01908e76aa94f1d5b83980e979a2216c to your computer and use it in GitHub Desktop.
Actix-web paperclip UUID test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "testing" | |
version = "0.1.0" | |
authors = ["Ravi Shankar <[email protected]>"] | |
edition = "2018" | |
[dependencies] | |
actix-web = "2.0" | |
serde = "1.0" | |
uuid = { version = "0.8", features = ["serde", "v4"] } | |
actix-rt = "1.0" | |
paperclip = { git = "https://github.com/wafflespeanut/paperclip", features = ["actix", "uid"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use actix_web::{App, HttpServer}; | |
use paperclip::actix::{ | |
OpenApiExt, api_v2_schema, api_v2_operation, | |
web::{self, Json}, | |
}; | |
use serde::{Serialize, Deserialize}; | |
#[api_v2_schema] | |
#[derive(Serialize, Deserialize)] | |
struct Pet { | |
name: String, | |
id: Option<uuid::Uuid>, | |
} | |
#[api_v2_operation] | |
async fn add_pet(body: Json<Pet>) -> Result<Json<Pet>, ()> { | |
Ok(body) | |
} | |
#[actix_rt::main] | |
async fn main() -> std::io::Result<()> { | |
HttpServer::new(|| App::new() | |
.wrap_api() | |
.with_json_spec_at("/api/spec") | |
.service( | |
web::resource("/pets") | |
.route(web::post().to(add_pet)) | |
) | |
.build() | |
).bind("127.0.0.1:8080")? | |
.run().await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment