File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5757
5858# ## Success Response
5959
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.
6161
6262` ` ` ruby
6363# in controller actions
6464data = { a: 1, b: 2 }
6565return success_response(data) if success?
6666` ` `
6767
68+ > response status: 200
69+ > response body:
70+
6871` ` ` json
69- // response status: 200
70- // response body:
7172{
7273 "data": {
7374 "a": 1,
@@ -85,9 +86,10 @@ The error response is used when the request is not valid. Therefore, you need to
8586return error_response(:bad_request_1) if failed?
8687` ` `
8788
89+ > response status: 400
90+ > response body:
91+
8892` ` ` json
89- // response status: 400
90- // response body:
9193{
9294 "error_code": 400_001,
9395 "error_message": "bad request 1",
@@ -102,9 +104,10 @@ You can also provide your custom error message and error data. If error data is
102104return error_response(:bad_request_1, 'no required data', { a: 1, b: 2 }) if failed?
103105` ` `
104106
107+ > response status: 400
108+ > response body:
109+
105110` ` ` json
106- // response status: 400
107- // response body:
108111{
109112 "error_code": 400_001,
110113 "error_message": "bad request 1: no required data",
@@ -140,9 +143,10 @@ ErrorResponse.to_hash(:bad_request_1)
140143
141144gives you
142145
146+ > response status: 400
147+ > response body:
148+
143149` ` ` json
144- // response status: 400
145- // response body:
146150{
147151 "error_code": 400_001,
148152 "error_message": "bad request 1",
You can’t perform that action at this time.
0 commit comments