22[ ![ Installs] ( https://img.shields.io/packagist/dt/phpro/api-problem.svg )] ( https://packagist.org/packages/phpro/api-problem/stats )
33[ ![ Packagist] ( https://img.shields.io/packagist/v/phpro/api-problem.svg )] ( https://packagist.org/packages/phpro/api-problem )
44
5-
65# Api Problem
76
87This package provides a [ RFC7807] ( https://tools.ietf.org/html/rfc7807 ) Problem details implementation.
@@ -13,7 +12,6 @@ Since handling the exceptions is up to the framework, here is a list of known fr
1312
1413- ** Symfony** ` ^4.1 ` : [ ApiProblemBundle] ( https://www.github.com/phpro/api-problem-bundle )
1514
16-
1715## Installation
1816
1917``` sh
@@ -34,22 +32,26 @@ throw new ApiProblemException(
3432
3533### Built-in problems
3634
37- - [ ExceptionApiProblem] ( #exceptionapiproblem )
38- - [ ForbiddenProblem] ( #forbiddenproblem )
39- - [ HttpApiProblem] ( #httpapiproblem )
40- - [ NotFoundProblem] ( #notfoundproblem )
41- - [ UnauthorizedProblem] ( #unauthorizedproblem )
42- - [ ValidationApiProblem] ( #validationapiproblem )
43- - [ BadRequestProblem] ( #badrequestproblem )
44- - [ ConflictProblem] ( #conflictproblem )
45- - [ NotModifiedProblem] ( #notmodifiedproblem )
46- - [ MethodNotAllowedProblem] ( #methodnotallowedproblem )
47- - [ PreconditionFailedProblem] ( #preconditionfailedproblem )
48- - [ UnsupportedMediaTypeProblem] ( #unsupportedmediatypeproblem )
49- - [ IAmATeapotProblem] ( #iamateapotproblem )
50- - [ UnprocessableEntityProblem] ( #unprocessableentityproblem )
51- - [ LockedProblem] ( #lockedproblem )
52- - [ PreconditionRequiredProblem] ( #preconditionrequiredproblem )
35+ - General problems
36+ - [ ExceptionApiProblem] ( #exceptionapiproblem )
37+ - [ HttpApiProblem] ( #httpapiproblem )
38+
39+ - Symfony integration problems
40+ - [ ValidationApiProblem] ( #validationapiproblem )
41+
42+ - Http problems
43+ - 400 [ BadRequestProblem] ( #badrequestproblem )
44+ - 401 [ UnauthorizedProblem] ( #unauthorizedproblem )
45+ - 403 [ ForbiddenProblem] ( #forbiddenproblem )
46+ - 404 [ NotFoundProblem] ( #notfoundproblem )
47+ - 405 [ MethodNotAllowedProblem] ( #methodnotallowedproblem )
48+ - 409 [ ConflictProblem] ( #conflictproblem )
49+ - 412 [ PreconditionFailedProblem] ( #preconditionfailedproblem )
50+ - 415 [ UnsupportedMediaTypeProblem] ( #unsupportedmediatypeproblem )
51+ - 418 [ IAmATeapotProblem] ( #iamateapotproblem )
52+ - 422 [ UnprocessableEntityProblem] ( #unprocessableentityproblem )
53+ - 423 [ LockedProblem] ( #lockedproblem )
54+ - 428 [ PreconditionRequiredProblem] ( #preconditionrequiredproblem )
5355
5456#### ExceptionApiProblem
5557
@@ -98,23 +100,6 @@ new ExceptionApiProblem(new \Exception('message', 500));
98100}
99101````
100102
101- #### ForbiddenProblem
102-
103- ```php
104- use Phpro\ApiProblem\Http\ForbiddenProblem;
105-
106- new ForbiddenProblem('Not authorized to access gold.');
107- ```
108-
109- ``` json
110- {
111- "status" : 403 ,
112- "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
113- "title" : " Forbidden" ,
114- "detail" : " Not authorized to access gold."
115- }
116- ````
117-
118103#### HttpApiProblem
119104
120105```php
@@ -132,40 +117,6 @@ new HttpApiProblem(404, ['detail' => 'The book could not be found.']);
132117}
133118````
134119
135- #### NotFoundProblem
136-
137- ```php
138- use Phpro\ApiProblem\Http\NotFoundProblem;
139-
140- new NotFoundProblem('The book with ID 20 could not be found.');
141- ```
142-
143- ``` json
144- {
145- "status" : 404 ,
146- "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
147- "title" : " Not found" ,
148- "detail" : " The book with ID 20 could not be found."
149- }
150- ````
151-
152- #### UnauthorizedProblem
153-
154- ```php
155- use Phpro\ApiProblem\Http\UnauthorizedProblem;
156-
157- new UnauthorizedProblem('You are not authorized to access X.');
158- ```
159-
160- ``` json
161- {
162- "status" : 401 ,
163- "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
164- "title" : " Unauthorized" ,
165- "detail" : " You are not authenticated. Please login."
166- }
167- ````
168-
169120#### ValidationApiProblem
170121
171122```sh
@@ -215,36 +166,54 @@ new BadRequestProblem('Bad request. Bad!.');
215166}
216167````
217168
218- #### ConflictProblem
169+ #### UnauthorizedProblem
219170
220171```php
221- use Phpro\ApiProblem\Http\ConflictProblem;
222- new ConflictProblem('Duplicated key for book with ID 20.');
172+ use Phpro\ApiProblem\Http\UnauthorizedProblem;
173+
174+ new UnauthorizedProblem('You are not authorized to access X.');
223175```
224176
225177``` json
226178{
227- "status" : 409 ,
179+ "status" : 401 ,
228180 "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
229- "title" : " Conflict" ,
230- "detail" : " Duplicated key for book with ID 20."
181+ "title" : " Unauthorized" ,
182+ "detail" : " You are not authenticated. Please login."
183+ }
184+ ````
185+
186+ #### ForbiddenProblem
187+
188+ ```php
189+ use Phpro\ApiProblem\Http\ForbiddenProblem;
190+
191+ new ForbiddenProblem('Not authorized to access gold.');
192+ ```
193+
194+ ``` json
195+ {
196+ "status" : 403 ,
197+ "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
198+ "title" : " Forbidden" ,
199+ "detail" : " Not authorized to access gold."
231200}
232201````
233202
234- #### NotModifiedProblem
203+ #### NotFoundProblem
235204
236205```php
237- use Phpro\ApiProblem\Http\NotModifiedProblem ;
206+ use Phpro\ApiProblem\Http\NotFoundProblem ;
238207
239- new NotModifiedProblem('Nothing has changed! .');
208+ new NotFoundProblem('The book with ID 20 could not be found .');
240209```
241210
242211``` json
243212{
244- "status" : 304 ,
213+ "status" : 404 ,
245214 "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
246- "title" : " Not Modified " ,
247- "detail" : " Nothing has changed! "
215+ "title" : " Not found " ,
216+ "detail" : " The book with ID 20 could not be found. "
248217}
249218````
250219
@@ -265,6 +234,22 @@ new MethodNotAllowedProblem('Only POST and GET allowed.');
265234}
266235````
267236
237+ #### ConflictProblem
238+
239+ ```php
240+ use Phpro\ApiProblem\Http\ConflictProblem;
241+ new ConflictProblem('Duplicated key for book with ID 20.');
242+ ```
243+
244+ ``` json
245+ {
246+ "status" : 409 ,
247+ "type" : " http:\/\/ www.w3.org\/ Protocols\/ rfc2616\/ rfc2616-sec10.html" ,
248+ "title" : " Conflict" ,
249+ "detail" : " Duplicated key for book with ID 20."
250+ }
251+ ````
252+
268253#### PreconditionFailedProblem
269254
270255```php
0 commit comments