Skip to content

Commit d4a36d4

Browse files
committed
update readme
1 parent 77a0081 commit d4a36d4

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

readme.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ response
5555
* [with item](#with-item)
5656
* [with collection](#with-collection)
5757
* [error](#error)
58+
* [with-error](#with-error)
5859
* [403 Forbidden](#403-forbidden)
5960
* [500 Internal Server Error](#500-internal-server-error)
6061
* [404 Not Found](#404-not-found)
6162
* [401 Unauthorized](#401-unauthorized)
6263
* [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)
6368

6469
##### With Array
6570
```php
@@ -88,10 +93,10 @@ use PhpRestfulApiResponse\Tests\unit\Lib\Book;
8893
echo $response->withItem(
8994
new Book('harry', 'harryosmarsitohang@gmail.com', 'how to be a ninja', 100000, 2017),
9095
new \PhpRestfulApiResponse\Tests\unit\Lib\Transformer\Book,
91-
200 //response code 200
96+
201 //response code 200
9297
);
9398
```
94-
response
99+
response 201
95100
```json
96101
{
97102
"data":
@@ -124,7 +129,7 @@ $response->withCollection(
124129
200
125130
);
126131
```
127-
response
132+
response 200
128133
```json
129134
{
130135
"data": [
@@ -163,13 +168,26 @@ response
163168

164169
#### Error
165170

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+
166184
##### 403 Forbidden
167185
```php
168186
<?php
169187
/** @var \PhpRestfulApiResponse\Response $response */
170188
echo $response->errorNotFound();
171189
```
172-
response
190+
response 403
173191
```json
174192
{
175193
"error":
@@ -186,7 +204,7 @@ response
186204
/** @var \PhpRestfulApiResponse\Response $response */
187205
echo $response->errorInternalError();
188206
```
189-
response
207+
response 500
190208
```json
191209
{
192210
"error":
@@ -203,7 +221,7 @@ response
203221
/** @var \PhpRestfulApiResponse\Response $response */
204222
echo $response->errorNotFound();
205223
```
206-
response
224+
response 404
207225
```json
208226
{
209227
"error":
@@ -220,7 +238,7 @@ response
220238
/** @var \PhpRestfulApiResponse\Response $response */
221239
echo $response->errorUnauthorized();
222240
```
223-
response
241+
response 401
224242
```json
225243
{
226244
"error":
@@ -240,7 +258,7 @@ echo $response->errorWrongArgs([
240258
'password' => 'required'
241259
]);
242260
```
243-
response
261+
response 400
244262
```json
245263
{
246264
"error":
@@ -262,24 +280,7 @@ response
262280
/** @var \PhpRestfulApiResponse\Response $response */
263281
echo $response->errorGone();
264282
```
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
283284
```json
284285
{
285286
"error":
@@ -296,7 +297,7 @@ response
296297
/** @var \PhpRestfulApiResponse\Response $response */
297298
echo $response->errorMethodNotAllowed();
298299
```
299-
response
300+
response 405
300301
```json
301302
{
302303
"error":
@@ -313,7 +314,7 @@ response
313314
/** @var \PhpRestfulApiResponse\Response $response */
314315
echo $response->errorUnwillingToProcess();
315316
```
316-
response
317+
response 431
317318
```json
318319
{
319320
"error":
@@ -330,7 +331,7 @@ response
330331
/** @var \PhpRestfulApiResponse\Response $response */
331332
echo $response->errorUnprocessable();
332333
```
333-
response
334+
response 422
334335
```json
335336
{
336337
"error":

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function withCollection($data, $transformer, $code = 200, $resourceKey =
232232
* Response for errors
233233
*
234234
* @param string|array $message
235-
* @param string $code
235+
* @param int $code
236236
* @param array $headers
237237
* @return mixed
238238
*/

0 commit comments

Comments
 (0)