happy-barney

IDEA - REST API Server with operations

Feb 12th, 2022 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # working name
  2.  
  3. use Safety::API::Dance;
  4.  
  5. resource "/v1/users"
  6. => abstract { 'Optional OpenAPI documentation' }
  7. => GET { operation 'list_users' }
  8. => PUT { operation 'create_user' }
  9. => POST { operations 'query_users' }
  10. ;
  11.  
  12. resource "/v1/users/:user_id"
  13. => GET { operation 'fetch_user' }
  14. => POST { operation 'update_user' }
  15. => DELETE { operation 'delete_user' }
  16. ;
  17.  
  18. resource parameter user_id
  19. => constraint => PositiveInt
  20. ;
  21.  
  22. operation delete_user
  23. => abstract { 'OpenAPI documentation' }
  24. => returns { constraint }
  25. => throws { HTTP::Status::NOT_FOUND => via 'My::API::X::User::Not::Found' }
  26. => throws { HTTP::Status::BAD_CONTENT => via 'My::API::X::User::Validation' }
  27. # either direct callback
  28. => as => sub { }
  29. # or delegate to the instance
  30. => class => 'My::API::Users'
  31. => method => 'delete'
  32. ;
  33.  
  34. # evolution of an idea (in fact this become before first step itself)
  35. # one declaration for uri with or without item identifier parameter
  36.  
  37. resource "/v1/users/:user_id"
  38. => abstract { 'Optional OpenAPI documentation' }
  39. => list_items { operation 'list_users' }
  40. => create_item { operation 'create_user' }
  41. => query_items { operations 'query_users' }
  42. => fetch_item { operation 'fetch_user' }
  43. => update_item { operation 'update_user' }
  44. => delete_item { operation 'delete_user' }
  45. ;
  46.  
Add Comment
Please, Sign In to add comment