Skip to content

Instantly share code, notes, and snippets.

@wafflespeanut
Created February 25, 2020 13:24
Show Gist options
  • Save wafflespeanut/01908e76aa94f1d5b83980e979a2216c to your computer and use it in GitHub Desktop.
Save wafflespeanut/01908e76aa94f1d5b83980e979a2216c to your computer and use it in GitHub Desktop.
Actix-web paperclip UUID test
[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"] }
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