You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,23 +57,23 @@ end
57
57
58
58
### Success Response
59
59
60
-
The success response is used when the request is success.
60
+
The success response is used when the request is success. The response body is a hash with a `data` key.
61
61
62
62
```ruby
63
63
# in controller actions
64
64
data = { a: 1, b: 2 }
65
65
return success_response(data) if success?
66
66
```
67
67
68
+
> response status: 200
69
+
> response body:
70
+
68
71
```json
69
72
{
70
-
"status": 200,
71
-
"json": {
72
-
"data": {
73
-
"a": 1,
74
-
"b": 2
75
-
}
76
-
}
73
+
"data": {
74
+
"a": 1,
75
+
"b": 2
76
+
}
77
77
}
78
78
```
79
79
@@ -86,38 +86,34 @@ The error response is used when the request is not valid. Therefore, you need to
86
86
return error_response(:bad_request_1) if failed?
87
87
```
88
88
89
+
> response status: 400
90
+
> response body:
91
+
89
92
```json
90
93
{
91
-
"status": 400,
92
-
"json":
93
-
{
94
-
"error_code": 400001,
95
-
"error_message": "bad request 1",
96
-
"error_key": "bad_request_1",
97
-
"a": 1,
98
-
"b": 2
99
-
}
94
+
"error_code": 400_001,
95
+
"error_message": "bad request 1",
96
+
"error_key": "bad_request_1"
100
97
}
101
98
```
102
99
103
-
You can also provide your custom error message and error data. If error data is a hash, it will be merged into the json response; if it is an array, it will be merged into the json response with an `error_data` key.
100
+
You can also provide your custom error message and error data. If error data is a hash, it will be merged into the json response; If it is an array, it will be merged into the json response with an `error_data` key.
0 commit comments