@@ -55,11 +55,16 @@ response
55
55
* [ with item] ( #with-item )
56
56
* [ with collection] ( #with-collection )
57
57
* [ error] ( #error )
58
+ * [ with-error] ( #with-error )
58
59
* [ 403 Forbidden] ( #403-forbidden )
59
60
* [ 500 Internal Server Error] ( #500-internal-server-error )
60
61
* [ 404 Not Found] ( #404-not-found )
61
62
* [ 401 Unauthorized] ( #401-unauthorized )
62
63
* [ 400 Bad Request] ( #400-bad-request )
64
+ * [ 410 Gone] ( #410-gone )
65
+ * [ 405 Method Not Allowed] ( #405-method-not-allowed )
66
+ * [ 431 Request Header Fields Too Large] ( #431-request-header-fields-too-large )
67
+ * [ 422 Unprocessable Entity] ( #422-unprocessable-entity )
63
68
64
69
##### With Array
65
70
``` php
@@ -88,10 +93,10 @@ use PhpRestfulApiResponse\Tests\unit\Lib\Book;
88
93
echo $response->withItem(
89
94
new Book('harry', 'harryosmarsitohang@gmail.com', 'how to be a ninja', 100000, 2017),
90
95
new \PhpRestfulApiResponse\Tests\unit\Lib\Transformer\Book,
91
- 200 //response code 200
96
+ 201 //response code 200
92
97
);
93
98
```
94
- response
99
+ response 201
95
100
``` json
96
101
{
97
102
"data" :
@@ -124,7 +129,7 @@ $response->withCollection(
124
129
200
125
130
);
126
131
```
127
- response
132
+ response 200
128
133
``` json
129
134
{
130
135
"data" : [
@@ -163,13 +168,26 @@ response
163
168
164
169
#### Error
165
170
171
+ ##### With Error
172
+ ``` php
173
+ <?php
174
+ /** @var \PhpRestfulApiResponse\Response $response */
175
+ echo $response->withError(['error' => 'something is wrong, please try again'], 500);
176
+ ```
177
+ response 500
178
+ ``` json
179
+ {
180
+ "error" : " something is wrong, please try again"
181
+ }
182
+ ```
183
+
166
184
##### 403 Forbidden
167
185
``` php
168
186
<?php
169
187
/** @var \PhpRestfulApiResponse\Response $response */
170
188
echo $response->errorNotFound();
171
189
```
172
- response
190
+ response 403
173
191
``` json
174
192
{
175
193
"error" :
@@ -186,7 +204,7 @@ response
186
204
/** @var \PhpRestfulApiResponse\Response $response */
187
205
echo $response->errorInternalError();
188
206
```
189
- response
207
+ response 500
190
208
``` json
191
209
{
192
210
"error" :
@@ -203,7 +221,7 @@ response
203
221
/** @var \PhpRestfulApiResponse\Response $response */
204
222
echo $response->errorNotFound();
205
223
```
206
- response
224
+ response 404
207
225
``` json
208
226
{
209
227
"error" :
@@ -220,7 +238,7 @@ response
220
238
/** @var \PhpRestfulApiResponse\Response $response */
221
239
echo $response->errorUnauthorized();
222
240
```
223
- response
241
+ response 401
224
242
``` json
225
243
{
226
244
"error" :
@@ -240,7 +258,7 @@ echo $response->errorWrongArgs([
240
258
'password' => 'required'
241
259
]);
242
260
```
243
- response
261
+ response 400
244
262
``` json
245
263
{
246
264
"error" :
@@ -262,24 +280,7 @@ response
262
280
/** @var \PhpRestfulApiResponse\Response $response */
263
281
echo $response->errorGone();
264
282
```
265
- response
266
- ``` json
267
- {
268
- "error" :
269
- {
270
- "http_code" : 410 ,
271
- "phrase" : " Unauthorized"
272
- }
273
- }
274
- ```
275
-
276
- ##### 410 Gone
277
- ``` php
278
- <?php
279
- /** @var \PhpRestfulApiResponse\Response $response */
280
- echo $response->errorGone();
281
- ```
282
- response
283
+ response 410
283
284
``` json
284
285
{
285
286
"error" :
@@ -296,7 +297,7 @@ response
296
297
/** @var \PhpRestfulApiResponse\Response $response */
297
298
echo $response->errorMethodNotAllowed();
298
299
```
299
- response
300
+ response 405
300
301
``` json
301
302
{
302
303
"error" :
@@ -313,7 +314,7 @@ response
313
314
/** @var \PhpRestfulApiResponse\Response $response */
314
315
echo $response->errorUnwillingToProcess();
315
316
```
316
- response
317
+ response 431
317
318
``` json
318
319
{
319
320
"error" :
@@ -330,7 +331,7 @@ response
330
331
/** @var \PhpRestfulApiResponse\Response $response */
331
332
echo $response->errorUnprocessable();
332
333
```
333
- response
334
+ response 422
334
335
``` json
335
336
{
336
337
"error" :
0 commit comments