jpie 0.4.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.cursor/rules/release.mdc +62 -0
  3. data/.gitignore +26 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +76 -107
  6. data/.travis.yml +7 -0
  7. data/Gemfile +23 -0
  8. data/Gemfile.lock +321 -0
  9. data/README.md +1508 -136
  10. data/Rakefile +3 -14
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/jpie.gemspec +21 -38
  14. data/kiln/app/resources/user_message_resource.rb +4 -0
  15. data/lib/jpie.rb +3 -25
  16. data/lib/json_api/active_storage/deserialization.rb +116 -0
  17. data/lib/json_api/active_storage/detection.rb +69 -0
  18. data/lib/json_api/active_storage/serialization.rb +34 -0
  19. data/lib/json_api/configuration.rb +57 -0
  20. data/lib/json_api/controllers/base_controller.rb +26 -0
  21. data/lib/json_api/controllers/concerns/controller_helpers/authorization.rb +30 -0
  22. data/lib/json_api/controllers/concerns/controller_helpers/document_meta.rb +20 -0
  23. data/lib/json_api/controllers/concerns/controller_helpers/error_rendering.rb +64 -0
  24. data/lib/json_api/controllers/concerns/controller_helpers/parsing.rb +127 -0
  25. data/lib/json_api/controllers/concerns/controller_helpers/resource_setup.rb +38 -0
  26. data/lib/json_api/controllers/concerns/controller_helpers.rb +19 -0
  27. data/lib/json_api/controllers/concerns/relationships/active_storage_removal.rb +65 -0
  28. data/lib/json_api/controllers/concerns/relationships/events.rb +44 -0
  29. data/lib/json_api/controllers/concerns/relationships/removal.rb +92 -0
  30. data/lib/json_api/controllers/concerns/relationships/response_helpers.rb +55 -0
  31. data/lib/json_api/controllers/concerns/relationships/serialization.rb +72 -0
  32. data/lib/json_api/controllers/concerns/relationships/sorting.rb +114 -0
  33. data/lib/json_api/controllers/concerns/relationships/updating.rb +73 -0
  34. data/lib/json_api/controllers/concerns/relationships_controller/active_storage_removal.rb +67 -0
  35. data/lib/json_api/controllers/concerns/relationships_controller/events.rb +44 -0
  36. data/lib/json_api/controllers/concerns/relationships_controller/removal.rb +92 -0
  37. data/lib/json_api/controllers/concerns/relationships_controller/response_helpers.rb +55 -0
  38. data/lib/json_api/controllers/concerns/relationships_controller/serialization.rb +72 -0
  39. data/lib/json_api/controllers/concerns/relationships_controller/sorting.rb +114 -0
  40. data/lib/json_api/controllers/concerns/relationships_controller/updating.rb +73 -0
  41. data/lib/json_api/controllers/concerns/resource_actions/crud_helpers.rb +93 -0
  42. data/lib/json_api/controllers/concerns/resource_actions/field_validation.rb +114 -0
  43. data/lib/json_api/controllers/concerns/resource_actions/filter_validation.rb +91 -0
  44. data/lib/json_api/controllers/concerns/resource_actions/pagination.rb +51 -0
  45. data/lib/json_api/controllers/concerns/resource_actions/preloading.rb +64 -0
  46. data/lib/json_api/controllers/concerns/resource_actions/resource_loading.rb +71 -0
  47. data/lib/json_api/controllers/concerns/resource_actions/serialization.rb +63 -0
  48. data/lib/json_api/controllers/concerns/resource_actions/type_validation.rb +75 -0
  49. data/lib/json_api/controllers/concerns/resource_actions.rb +106 -0
  50. data/lib/json_api/controllers/relationships_controller.rb +108 -0
  51. data/lib/json_api/controllers/resources_controller.rb +6 -0
  52. data/lib/json_api/errors/parameter_not_allowed.rb +19 -0
  53. data/lib/json_api/railtie.rb +112 -0
  54. data/lib/json_api/resources/active_storage_blob_resource.rb +19 -0
  55. data/lib/json_api/resources/concerns/attributes_dsl.rb +69 -0
  56. data/lib/json_api/resources/concerns/filters_dsl.rb +32 -0
  57. data/lib/json_api/resources/concerns/meta_dsl.rb +23 -0
  58. data/lib/json_api/resources/concerns/model_class_helpers.rb +37 -0
  59. data/lib/json_api/resources/concerns/relationships_dsl.rb +71 -0
  60. data/lib/json_api/resources/concerns/sortable_fields_dsl.rb +36 -0
  61. data/lib/json_api/resources/resource.rb +32 -0
  62. data/lib/json_api/resources/resource_loader.rb +35 -0
  63. data/lib/json_api/routing.rb +81 -0
  64. data/lib/json_api/serialization/concerns/attributes_deserialization.rb +27 -0
  65. data/lib/json_api/serialization/concerns/attributes_serialization.rb +50 -0
  66. data/lib/json_api/serialization/concerns/deserialization_helpers.rb +115 -0
  67. data/lib/json_api/serialization/concerns/includes_serialization.rb +82 -0
  68. data/lib/json_api/serialization/concerns/links_serialization.rb +33 -0
  69. data/lib/json_api/serialization/concerns/meta_serialization.rb +60 -0
  70. data/lib/json_api/serialization/concerns/model_attributes_transformation.rb +69 -0
  71. data/lib/json_api/serialization/concerns/relationship_processing.rb +119 -0
  72. data/lib/json_api/serialization/concerns/relationships_deserialization.rb +47 -0
  73. data/lib/json_api/serialization/concerns/relationships_serialization.rb +81 -0
  74. data/lib/json_api/serialization/deserializer.rb +26 -0
  75. data/lib/json_api/serialization/serializer.rb +77 -0
  76. data/lib/json_api/support/active_storage_support.rb +82 -0
  77. data/lib/json_api/support/collection_query.rb +50 -0
  78. data/lib/json_api/support/concerns/condition_building.rb +57 -0
  79. data/lib/json_api/support/concerns/nested_filters.rb +130 -0
  80. data/lib/json_api/support/concerns/pagination.rb +30 -0
  81. data/lib/json_api/support/concerns/polymorphic_filters.rb +75 -0
  82. data/lib/json_api/support/concerns/regular_filters.rb +81 -0
  83. data/lib/json_api/support/concerns/sorting.rb +88 -0
  84. data/lib/json_api/support/instrumentation.rb +43 -0
  85. data/lib/json_api/support/param_helpers.rb +54 -0
  86. data/lib/json_api/support/relationship_guard.rb +16 -0
  87. data/lib/json_api/support/relationship_helpers.rb +76 -0
  88. data/lib/json_api/support/resource_identifier.rb +87 -0
  89. data/lib/json_api/support/responders.rb +100 -0
  90. data/lib/json_api/support/response_helpers.rb +10 -0
  91. data/lib/json_api/support/sort_parsing.rb +21 -0
  92. data/lib/json_api/support/type_conversion.rb +21 -0
  93. data/lib/json_api/testing/test_helper.rb +76 -0
  94. data/lib/json_api/testing.rb +3 -0
  95. data/lib/{jpie → json_api}/version.rb +2 -2
  96. data/lib/json_api.rb +50 -0
  97. data/lib/rubocop/cop/custom/hash_value_omission.rb +53 -0
  98. metadata +100 -169
  99. data/.cursor/rules/dependencies.mdc +0 -19
  100. data/.cursor/rules/examples.mdc +0 -16
  101. data/.cursor/rules/git.mdc +0 -14
  102. data/.cursor/rules/project_structure.mdc +0 -30
  103. data/.cursor/rules/publish_gem.mdc +0 -73
  104. data/.cursor/rules/security.mdc +0 -14
  105. data/.cursor/rules/style.mdc +0 -15
  106. data/.cursor/rules/testing.mdc +0 -16
  107. data/.overcommit.yml +0 -35
  108. data/CHANGELOG.md +0 -164
  109. data/LICENSE.txt +0 -21
  110. data/PUBLISHING.md +0 -111
  111. data/examples/basic_example.md +0 -146
  112. data/examples/including_related_resources.md +0 -491
  113. data/examples/pagination.md +0 -303
  114. data/examples/relationships.md +0 -114
  115. data/examples/resource_attribute_configuration.md +0 -147
  116. data/examples/resource_meta_configuration.md +0 -244
  117. data/examples/rspec_testing.md +0 -130
  118. data/examples/single_table_inheritance.md +0 -160
  119. data/lib/jpie/configuration.rb +0 -12
  120. data/lib/jpie/controller/crud_actions.rb +0 -141
  121. data/lib/jpie/controller/error_handling/handler_setup.rb +0 -124
  122. data/lib/jpie/controller/error_handling/handlers.rb +0 -109
  123. data/lib/jpie/controller/error_handling.rb +0 -23
  124. data/lib/jpie/controller/json_api_validation.rb +0 -193
  125. data/lib/jpie/controller/parameter_parsing.rb +0 -78
  126. data/lib/jpie/controller/related_actions.rb +0 -45
  127. data/lib/jpie/controller/relationship_actions.rb +0 -291
  128. data/lib/jpie/controller/relationship_validation.rb +0 -117
  129. data/lib/jpie/controller/rendering.rb +0 -154
  130. data/lib/jpie/controller.rb +0 -45
  131. data/lib/jpie/deserializer.rb +0 -110
  132. data/lib/jpie/errors.rb +0 -117
  133. data/lib/jpie/generators/resource_generator.rb +0 -116
  134. data/lib/jpie/generators/templates/resource.rb.erb +0 -31
  135. data/lib/jpie/railtie.rb +0 -42
  136. data/lib/jpie/resource/attributable.rb +0 -112
  137. data/lib/jpie/resource/inferrable.rb +0 -43
  138. data/lib/jpie/resource/sortable.rb +0 -93
  139. data/lib/jpie/resource.rb +0 -147
  140. data/lib/jpie/routing.rb +0 -59
  141. data/lib/jpie/serializer.rb +0 -205
data/CHANGELOG.md DELETED
@@ -1,164 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## [0.4.2] - 2025-01-25
11
-
12
- ### Added
13
- - **Pagination Example**: Comprehensive pagination example demonstrating both simple and JSON:API standard pagination formats
14
- - Simple pagination parameters (`page`, `per_page`)
15
- - JSON:API standard pagination format (`page[number]`, `page[size]`)
16
- - Pagination combined with sorting functionality
17
- - Edge cases including last page and empty results
18
- - Complete HTTP request/response examples following project format
19
-
20
- ### Enhanced
21
- - **Documentation**: Improved example coverage with detailed pagination use cases
22
- - **Developer Experience**: Clear examples for implementing pagination in JPie applications
23
-
24
- ## [0.4.1] - 2025-01-25
25
-
26
- ### Fixed
27
- - **Test Suite Stability**: Fixed require statements in spec files that were incorrectly requiring `rails_helper` instead of `spec_helper`
28
- - Fixed `spec/jpie/automatic_crud_spec.rb`
29
- - Fixed `spec/jpie/polymorphic_crud_spec.rb`
30
- - Fixed `spec/jpie/through_associations_crud_spec.rb`
31
- - **Code Quality**: Addressed RuboCop warnings and improved code style compliance
32
- - **Error Handling**: Improved error message consistency for unsupported sort fields and include parameters
33
-
34
- ### Enhanced
35
- - **Test Coverage**: Maintained high test coverage (93.39%) with improved test reliability
36
- - **Documentation**: Updated gem publishing workflow and development guidelines
37
-
38
- ### Technical Details
39
- - All spec files now correctly use `spec_helper` for consistent test environment setup
40
- - Improved gem build process with proper dependency management
41
- - Enhanced RuboCop configuration for better code quality enforcement
42
-
43
- ## [0.4.0] - 2025-01-25
44
-
45
- ### Added
46
- - **Semantic Generator Syntax**: Complete rewrite of resource generator with JSON:API-focused field categorization
47
- - `attribute:field` - Explicit JSON:API attribute definition
48
- - `meta:field` - Explicit JSON:API meta attribute definition
49
- - `has_many:resource` - Shorthand relationship syntax
50
- - `relationship:type:field` - Explicit relationship syntax
51
- - **Improved Developer Experience**: More intuitive and semantic generator approach focused on JSON:API concepts rather than database types
52
-
53
- ### Enhanced
54
- - **Generator Logic**: Refactored generator into cleaner, more maintainable methods with proper separation of concerns
55
- - **Backward Compatibility**: Legacy `field:type` syntax fully preserved - existing usage continues to work unchanged
56
- - **Code Quality**: Fixed all RuboCop violations in generator code with improved method structure
57
- - **Test Coverage**: Comprehensive test suite covering semantic syntax, legacy compatibility, and all feature combinations
58
-
59
- ### Improved
60
- - **Generator Syntax**: Replaced meaningless database types (`name:string`) with semantic JSON:API categorization (`attribute:name`)
61
- - **Documentation**: README completely updated to showcase new semantic approach with comprehensive examples
62
- - **Generator Help**: Updated help text and banners to reflect new semantic syntax
63
-
64
- ### Technical Details
65
- - Generator automatically categorizes fields based on semantic prefixes
66
- - Auto-detection of common meta attributes (`created_at`, `updated_at`, etc.) preserved
67
- - Relationship inference and resource class detection maintained
68
- - All 373 tests pass with 95.97% coverage maintained
69
-
70
- ### Migration Guide
71
- - **New syntax (recommended)**: `rails generate jpie:resource User attribute:name meta:created_at has_many:posts`
72
- - **Legacy syntax (still works)**: `rails generate jpie:resource User name:string created_at:datetime --relationships=has_many:posts`
73
- - No breaking changes - existing generators continue to work as before
74
-
75
- ## [0.3.1] - 2025-01-24
76
-
77
- ### Fixed
78
- - **Gemspec Metadata**: Updated homepage URL to correct GitHub repository (https://github.com/emk-klaay/jpie)
79
- - **Documentation Links**: Fixed source code and changelog URLs in gem metadata
80
-
81
- ## [0.3.0] - 2025-01-24
82
-
83
- ### Added
84
- - **Modern DSL Aliases**: Introduced concise aliases following Rails conventions
85
- - `render_jsonapi` - Single method for rendering both resources and collections
86
- - `resource` - Concise alias for `jsonapi_resource` in controllers
87
- - `meta` and `metas` - Short aliases for `meta_attribute` and `meta_attributes`
88
- - `sortable` - Concise alias for `sortable_by` in resources
89
- - **Method Override Support**: Custom attribute methods can now be defined directly on resource classes
90
- - Support for both public and private method definitions
91
- - Access to `object` and `context` within custom methods
92
- - Method precedence: blocks → options blocks → custom methods → model attributes
93
- - **Enhanced Documentation**: Comprehensive README updates with Key Features section and modern DSL examples
94
-
95
- ### Enhanced
96
- - **Controller DSL**: Simplified rendering with intelligent `render_jsonapi` method that handles both single resources and collections automatically
97
- - **Resource DSL**: More intuitive and concise method names aligned with modern Rails patterns
98
- - **Backward Compatibility**: All original method names preserved via aliases - no breaking changes
99
- - **Code Quality**: 100% test coverage maintained with 363 passing tests and full RuboCop compliance
100
-
101
- ### Improved
102
- - **Developer Experience**: Cleaner, more intuitive API that follows Rails conventions
103
- - **IDE Support**: Better support for custom attribute methods with proper method definitions
104
- - **Testing**: Easier testing of individual custom methods vs block-based approaches
105
- - **Performance**: Method-based attributes avoid block overhead for simple transformations
106
-
107
- ### Technical Details
108
- - Custom methods support both public and private visibility
109
- - Intelligent method detection prevents overriding existing custom implementations
110
- - All render methods consolidated into single polymorphic `render_jsonapi` method
111
- - Full backward compatibility ensures seamless upgrades
112
-
113
- ## [0.2.0] - 2025-01-24
114
-
115
- ### Added
116
- - **Single Table Inheritance (STI) Support**: Comprehensive support for Rails STI models with automatic type inference, resource inheritance, and polymorphic serialization
117
- - **Custom Meta Method**: Resources can now define a `meta` method to provide dynamic meta data alongside the existing `meta_attributes` macro, with access to `object`, `context`, and ability to call `super`
118
- - **Enhanced Test Coverage**: Added comprehensive test suites for STI and meta method functionality with 95.13% line coverage
119
- - **RuboCop Configuration**: Improved RuboCop configuration for test files, reducing offenses from 247 to 0 while maintaining code quality
120
-
121
- ### Enhanced
122
- - **STI Models**: Automatic JSON:API type inference from STI model classes (e.g., `Car` model → `"cars"` type)
123
- - **STI Resources**: Seamless resource inheritance matching model inheritance patterns
124
- - **STI Serialization**: Each STI model serializes with correct type and specific attributes
125
- - **STI Controllers**: Automatic scoping to specific STI types while supporting polymorphic queries
126
- - **Meta Method Features**: Dynamic meta data generation with context access and inheritance support
127
- - **Documentation**: Comprehensive README updates with STI examples and meta method usage
128
-
129
- ### Improved
130
- - **Test Suite**: 343 tests covering all functionality including complex STI scenarios
131
- - **Code Quality**: Zero RuboCop offenses with reasonable configuration for comprehensive test suites
132
- - **Error Handling**: Proper validation for meta method return types with helpful error messages
133
-
134
- ### Technical Details
135
- - STI models automatically infer correct resource classes for polymorphic serialization
136
- - Meta methods can access `object`, `context`, and call `super` for attribute merging
137
- - RuboCop configuration optimized for integration tests without compromising production code standards
138
- - Comprehensive test coverage for edge cases and complex scenarios
139
-
140
- ## [0.1.0] - 2024-01-01
141
-
142
- ### Added
143
- - Initial release with core functionality
144
- - JSON:API compliant serialization and deserialization
145
- - Resource definition with attributes
146
- - Controller integration module
147
- - Rails generator for creating resources
148
- - Comprehensive error handling
149
- - Configuration system for key formats
150
- - Full test suite with RSpec
151
-
152
- ### Features
153
- - `JPie::Resource` - Base class for defining API resources
154
- - `JPie::Serializer` - Converts Ruby objects to JSON:API format
155
- - `JPie::Deserializer` - Converts JSON:API format to Ruby hashes
156
- - `JPie::Controller` - Rails integration module
157
- - `JPie::Configuration` - Gem-wide configuration management
158
- - `JPie::Errors` - JSON:API compliant error classes
159
- - Rails generator: `rails generate jpie:resource`
160
-
161
- ### Dependencies
162
- - Ruby >= 3.4.0
163
- - Rails >= 8.0.0
164
- - ActiveSupport >= 8.0.0
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Emil Kampp
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
data/PUBLISHING.md DELETED
@@ -1,111 +0,0 @@
1
- # Publishing JPie
2
-
3
- This guide explains how to publish new versions of the JPie gem to RubyGems.org.
4
-
5
- ## Prerequisites
6
-
7
- 1. Ensure you have a RubyGems.org account
8
- 2. Ensure you have ownership/publishing rights to the gem
9
- 3. Configure your local credentials:
10
- ```bash
11
- gem signin
12
- ```
13
-
14
- ## Publishing Process
15
-
16
- ### 1. Update Version
17
-
18
- Update the version number in `lib/jpie/version.rb`:
19
-
20
- ```ruby
21
- module JPie
22
- VERSION = "x.y.z" # Use semantic versioning
23
- end
24
- ```
25
-
26
- ### 2. Update Changelog
27
-
28
- Update `CHANGELOG.md` with the changes in the new version:
29
-
30
- ```markdown
31
- ## [x.y.z] - YYYY-MM-DD
32
-
33
- ### Added
34
- - New features
35
-
36
- ### Changed
37
- - Changes in existing functionality
38
-
39
- ### Deprecated
40
- - Soon-to-be removed features
41
-
42
- ### Removed
43
- - Removed features
44
-
45
- ### Fixed
46
- - Bug fixes
47
-
48
- ### Security
49
- - Security fixes
50
- ```
51
-
52
- ### 3. Build the Gem
53
-
54
- ```bash
55
- gem build jpie.gemspec
56
- ```
57
-
58
- This will create a file named `jpie-x.y.z.gem`.
59
-
60
- ### 4. Test the Gem Locally (Optional)
61
-
62
- ```bash
63
- # In a test project
64
- gem install ../path/to/jpie-x.y.z.gem
65
- ```
66
-
67
- ### 5. Push to RubyGems
68
-
69
- ```bash
70
- gem push jpie-x.y.z.gem
71
- ```
72
-
73
- ### 6. Tag the Release
74
-
75
- ```bash
76
- git add lib/jpie/version.rb CHANGELOG.md
77
- git commit -m "Release version x.y.z"
78
- git tag -a vx.y.z -m "Version x.y.z"
79
- git push origin main --tags
80
- ```
81
-
82
- ## Versioning Guidelines
83
-
84
- Follow [Semantic Versioning](https://semver.org/):
85
-
86
- - MAJOR version (x) - incompatible API changes
87
- - MINOR version (y) - add functionality in a backward compatible manner
88
- - PATCH version (z) - backward compatible bug fixes
89
-
90
- ## Troubleshooting
91
-
92
- ### Common Issues
93
-
94
- 1. **Authentication Failed**
95
- ```bash
96
- gem signin # Re-authenticate with RubyGems
97
- ```
98
-
99
- 2. **Gem Name Conflict**
100
- - Ensure the version number is unique
101
- - Check if the gem name is available on RubyGems.org
102
-
103
- 3. **Build Errors**
104
- - Ensure all dependencies are correctly specified in the gemspec
105
- - Verify the gem builds locally before pushing
106
-
107
- ### Getting Help
108
-
109
- - [RubyGems Guides](https://guides.rubygems.org/)
110
- - [Semantic Versioning](https://semver.org/)
111
- - Open an issue in the JPie repository
@@ -1,146 +0,0 @@
1
- # Basic JPie Example
2
-
3
- This example shows the minimal setup to get a JPie resource working with HTTP requests and responses.
4
-
5
- ## Setup
6
-
7
- ### 1. Model (`app/models/user.rb`)
8
- ```ruby
9
- class User < ActiveRecord::Base
10
- validates :name, presence: true
11
- validates :email, presence: true, uniqueness: true
12
- end
13
- ```
14
-
15
- ### 2. Resource (`app/resources/user_resource.rb`)
16
- ```ruby
17
- class UserResource < JPie::Resource
18
- attributes :name, :email
19
- end
20
- ```
21
-
22
- ### 3. Controller (`app/controllers/users_controller.rb`)
23
- ```ruby
24
- class UsersController < ApplicationController
25
- include JPie::Controller
26
- end
27
- ```
28
-
29
- ### 4. Routes (`config/routes.rb`)
30
- ```ruby
31
- Rails.application.routes.draw do
32
- resources :users
33
- end
34
- ```
35
-
36
- ## HTTP Examples
37
-
38
- ### Create User
39
- ```http
40
- POST /users
41
- Content-Type: application/vnd.api+json
42
-
43
- {
44
- "data": {
45
- "type": "users",
46
- "attributes": {
47
- "name": "John Doe",
48
- "email": "john@example.com"
49
- }
50
- }
51
- }
52
-
53
- HTTP/1.1 201 Created
54
- Content-Type: application/vnd.api+json
55
-
56
- {
57
- "data": {
58
- "id": "1",
59
- "type": "users",
60
- "attributes": {
61
- "name": "John Doe",
62
- "email": "john@example.com"
63
- }
64
- }
65
- }
66
- ```
67
-
68
- ### Get All Users
69
- ```http
70
- GET /users
71
- Accept: application/vnd.api+json
72
-
73
- HTTP/1.1 200 OK
74
- Content-Type: application/vnd.api+json
75
-
76
- {
77
- "data": [
78
- {
79
- "id": "1",
80
- "type": "users",
81
- "attributes": {
82
- "name": "John Doe",
83
- "email": "john@example.com"
84
- }
85
- }
86
- ]
87
- }
88
- ```
89
-
90
- ### Get Single User
91
- ```http
92
- GET /users/1
93
- Accept: application/vnd.api+json
94
-
95
- HTTP/1.1 200 OK
96
- Content-Type: application/vnd.api+json
97
-
98
- {
99
- "data": {
100
- "id": "1",
101
- "type": "users",
102
- "attributes": {
103
- "name": "John Doe",
104
- "email": "john@example.com"
105
- }
106
- }
107
- }
108
- ```
109
-
110
- ### Update User
111
- ```http
112
- PATCH /users/1
113
- Content-Type: application/vnd.api+json
114
-
115
- {
116
- "data": {
117
- "id": "1",
118
- "type": "users",
119
- "attributes": {
120
- "name": "Jane Doe"
121
- }
122
- }
123
- }
124
-
125
- HTTP/1.1 200 OK
126
- Content-Type: application/vnd.api+json
127
-
128
- {
129
- "data": {
130
- "id": "1",
131
- "type": "users",
132
- "attributes": {
133
- "name": "Jane Doe",
134
- "email": "john@example.com"
135
- }
136
- }
137
- }
138
- ```
139
-
140
- ### Delete User
141
- ```http
142
- DELETE /users/1
143
- Accept: application/vnd.api+json
144
-
145
- HTTP/1.1 204 No Content
146
- ```