Successfully reported this slideshow.

Building a Rails API with the JSON API Spec

5

Share

Upcoming SlideShare
Ember Data and JSON API
Ember Data and JSON API
Loading in …3
×
1 of 73
1 of 73

Building a Rails API with the JSON API Spec

5

Share

Download to read offline

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.

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.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

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

×