Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Building a
JSON API Spec
Rails API
with the
billing
service
service
managing
ads
add items
front end
user facing
show & update
accounts
external
payment provider
new
...
book data
service
front end
user facing
show me
books
update
books
front end
admin
API goals:
flexible
API goals:
consistent
flexible
API goals:
consistent
flexible
fast
API goals:
enter
JSON API
API goals:
flexible
API goals:
consistent
flexible
API goals:
consistent
flexible
fast
API goals:
bikeshedding
generalized
libraries &
tooling
made it?
Who
Whyam I
about it?
talking
How does it
work?
strict requirements:
including related
resources
creating & updating
resources
fetching resources
manipulating
relationshi...
paginationsorting
filtering
sparse fieldsets
some requirements/guidelines:
including links
errors
up to you:
URL design
how resources map
to actual stored data
authentication
authorization
Fetching a resource: GET /books/2
Fetching a resource: GET /books/2
JSON API document
Fetching a resource: GET /books/2
resource object
Fetching a resource: GET /books/2
resource identifier
objects
Fetching a collection of resources: GET /books
Fetching a collection of resources: GET /books
array of resource objects
Using include: GET /books?include=author,editorial_tags
Using include: GET /books?include=author,editorial_tags
Using include: GET /books?include=author,editorial_tags
why
not
nest?
GET /books?include=tags,author.tags
Including multiple levels
GET /books?include=author
&fields[authors]=name
&fields[books]=title
Sparse fieldsets:
Creating a resource:
POST /books
PATCH /books/2
Updating a resource:
DELETE /books/2
Deleting a resource:
Links
Links
resource level links object
Links
resource level links object
relationship level links object
https://example.com/books/1/relationships/author
https://example.com/books/1/author
related link:
self link:
relationship ...
PATCH
/books/2/relationships/author
paginationsorting
filtering
sparse fieldsets
some requirements/guidelines:
including links
errors
JSON API
Ruby on Rails
+
convention
configuration
Active Model Serializers
JSONAPI::Resources
vs
just serialization
full server side flow
vs
more control
more magic
vs
lots more libraries!
http://jsonapi.org/implementations/#client-libraries-ruby
http://jsonapi.org/implementations/#server-...
should
youuse it?
bikeshedding
What can go in an error object?
What can go in an error object?
id and/or links and/or status
and/or meta and/or detail
and/or code and/or title and/
or m...
the bike shed
the nuclear plant
???
the bike shed
the nuclear plant
limitations:
creating a resource
and its relationships
at the same time
multiple operations
in one request
limitations:
creating a resource
and its relationships
at the same time
multiple operations
in one request
current
widely applicable
effectivesimple
widely applicable
effectivesimple
pick two?
nothing
free
in life is
API goals:
flexible
API goals:
consistent
flexible
API goals:
consistent
flexible
fast
API goals:
initial
larger
cost
payoff?term
long-term
consistency & flexibility
large collections
of data with
in one request
yes
have time
up front
to investrelationships
large...
need multi
operation
requests
easy to update
clients
no
simplicity & speed
priorities:
don’t want
dependencies
should
youuse it?
you
www.bookbub.com/careers
@SonjaBPeterson
also, we’re hiring!
Questions?
on twitter
Building a Rails API with the JSON API Spec
Building a Rails API with the JSON API Spec
Building a Rails API with the JSON API Spec
Building a Rails API with the JSON API Spec
Building a Rails API with the JSON API Spec
Prochain SlideShare
Chargement dans…5
×

Building a Rails API with the JSON API Spec

789 vues

Publié le

So you're building a Rails API and you want to do it right--following RESTful best practices, with endpoints that can sideload related resources, paginate and filter with grace. The JSON API Specification (jsonapi.org) aims to help you do this without spending a month bikeshedding or reinventing the wheel. But does it really work? Based on my experience using it in my last project, this talk will help you decide whether to use it and how to do so with Rails.

Publié dans : Logiciels
  • NOTE TO READERS: Do NOT Buy Any Shed Plans Until You've Seen This... =>> https://t.cn/A62Ydb8v
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Building a Rails API with the JSON API Spec

  1. 1. Building a JSON API Spec Rails API with the
  2. 2. billing service service managing ads add items front end user facing show & update accounts external payment provider new to autobill
  3. 3. book data service front end user facing show me books update books front end admin
  4. 4. API goals:
  5. 5. flexible API goals:
  6. 6. consistent flexible API goals:
  7. 7. consistent flexible fast API goals:
  8. 8. enter JSON API
  9. 9. API goals:
  10. 10. flexible API goals:
  11. 11. consistent flexible API goals:
  12. 12. consistent flexible fast API goals:
  13. 13. bikeshedding
  14. 14. generalized libraries & tooling
  15. 15. made it? Who
  16. 16. Whyam I about it? talking
  17. 17. How does it work?
  18. 18. strict requirements: including related resources creating & updating resources fetching resources manipulating relationships
  19. 19. paginationsorting filtering sparse fieldsets some requirements/guidelines: including links errors
  20. 20. up to you: URL design how resources map to actual stored data authentication authorization
  21. 21. Fetching a resource: GET /books/2
  22. 22. Fetching a resource: GET /books/2 JSON API document
  23. 23. Fetching a resource: GET /books/2 resource object
  24. 24. Fetching a resource: GET /books/2 resource identifier objects
  25. 25. Fetching a collection of resources: GET /books
  26. 26. Fetching a collection of resources: GET /books array of resource objects
  27. 27. Using include: GET /books?include=author,editorial_tags
  28. 28. Using include: GET /books?include=author,editorial_tags
  29. 29. Using include: GET /books?include=author,editorial_tags
  30. 30. why not nest?
  31. 31. GET /books?include=tags,author.tags Including multiple levels
  32. 32. GET /books?include=author &fields[authors]=name &fields[books]=title Sparse fieldsets:
  33. 33. Creating a resource: POST /books
  34. 34. PATCH /books/2 Updating a resource:
  35. 35. DELETE /books/2 Deleting a resource:
  36. 36. Links
  37. 37. Links resource level links object
  38. 38. Links resource level links object relationship level links object
  39. 39. https://example.com/books/1/relationships/author https://example.com/books/1/author related link: self link: relationship links:
  40. 40. PATCH /books/2/relationships/author
  41. 41. paginationsorting filtering sparse fieldsets some requirements/guidelines: including links errors
  42. 42. JSON API Ruby on Rails +
  43. 43. convention configuration
  44. 44. Active Model Serializers JSONAPI::Resources vs
  45. 45. just serialization full server side flow vs
  46. 46. more control more magic vs
  47. 47. lots more libraries! http://jsonapi.org/implementations/#client-libraries-ruby http://jsonapi.org/implementations/#server-libraries-ruby https://github.com/fotinakis/jsonapi-serializers
  48. 48. should youuse it?
  49. 49. bikeshedding
  50. 50. What can go in an error object?
  51. 51. What can go in an error object? id and/or links and/or status and/or meta and/or detail and/or code and/or title and/ or meta and/or source (with a pointer and/or a parameter)
  52. 52. the bike shed the nuclear plant
  53. 53. ??? the bike shed the nuclear plant
  54. 54. limitations: creating a resource and its relationships at the same time multiple operations in one request
  55. 55. limitations: creating a resource and its relationships at the same time multiple operations in one request current
  56. 56. widely applicable effectivesimple
  57. 57. widely applicable effectivesimple pick two?
  58. 58. nothing free in life is
  59. 59. API goals:
  60. 60. flexible API goals:
  61. 61. consistent flexible API goals:
  62. 62. consistent flexible fast API goals:
  63. 63. initial larger cost payoff?term long-term
  64. 64. consistency & flexibility large collections of data with in one request yes have time up front to investrelationships larger team priorities:
  65. 65. need multi operation requests easy to update clients no simplicity & speed priorities: don’t want dependencies
  66. 66. should youuse it?
  67. 67. you
  68. 68. www.bookbub.com/careers @SonjaBPeterson also, we’re hiring! Questions? on twitter

×