Skip to content

Instantly share code, notes, and snippets.

@goyox86
Created March 16, 2017 11:39
Show Gist options
  • Save goyox86/bf192c17cf578856ffdef07e3bf30069 to your computer and use it in GitHub Desktop.
Save goyox86/bf192c17cf578856ffdef07e3bf30069 to your computer and use it in GitHub Desktop.
#[post("/users", data = "<new_user>", format = "application/json")]
fn create(db: State<Db>, new_user: JSON<NewUser>) -> EndpointResult<JSON<User>> {
let conn = &*db.pool().get()?;
let new_user = NewUserReadyForInsertion::from(new_user.0);
let user = diesel::insert(&new_user).into(users::table)
.get_result::<User>(conn)?;
Ok(JSON(user))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment