PHPackages                             zircote/api-problem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zircote/api-problem

ActiveLibrary

zircote/api-problem
===================

An Api Problem Exception implementation in PHP. See: http://tools.ietf.org/html/draft-nottingham-http-problem for the latest on the specification

1120PHPCI passing

Since Feb 27Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/zircote/ApiProblem)[ Packagist](https://packagist.org/packages/zircote/api-problem)[ RSS](/packages/zircote-api-problem/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ApiProblem
==========

[](#apiproblem)

- [![Master Build Status](https://camo.githubusercontent.com/95ffb5237955c54168ade33f37feb8a122b7833040e25660f54f3740629721ff/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7a6972636f74652f41706950726f626c656d2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/zircote/ApiProblem) `master`

`ApiProblem` is an attempt to provide the functionality and problem reporting as defined in [Problem Details for HTTP APIs](http://tools.ietf.org/html/draft-nottingham-http-problem). The goal being a simple Exception wrapper for PHP that can send the desired response in `JSON` and `XML`.

Use
---

[](#use)

#### The `sendHttpResponse` method

[](#the-sendhttpresponse-method)

The `sendHTTPResponse` has two parameter, both optional `$format` and `$terminate`.

- `format`:
- `ApiProblem::FORMAT_XML`: `application/api-problem+json`
- `ApiProblem::FORMAT_JSON`: `application/api-problem+xml`
- `terminate`: `bool`
- `true` (default) headers are sent and execution is terminated.
- `false` the body payload is returned

#### JSON Example

[](#json-example)

```

    http://api-problem.domain.com/some-url.html
    Bad Request
    400
    some detail
    http://domain.com/this-request

```

#### Adding additional headers, i.e. CORS, Auth, etc

[](#adding-additional-headers-ie-cors-auth-etc)

```
