weierophinney/PhlyRestfully — pull request #48 by weierophinney (2013-04-27 12:13:20+00:00)
Title: API Problem Questions...

(This issue should probably be marked as a question.)

I'm currently focusing on implementing input handlers to filter and validate input on POST/create and PUT/update requests. When validation fails, I would like to make sure that an API Problem response with sufficient information is returned.

It's no problem returning an API Problem response, since PhlyRestfully does this automatically, for the most part. It's quite nice. I'm struggling, though, in trying to find ways to populate some of the Problem API fields.

Here's a typical response that might be returned from an invalid POST/create request:
```
{
"describedBy": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "PhlyRestfully\\Exception\\CreationException",
"httpStatus": 406,
"detail": "invalid input fields:mainContactId"
}
```
When I throw an exception, I'm throwing a ```PhlyRestfully\Exception\CreationException```, as you can see. I'm also setting the exception's ```code``` property to 406, which seems to be the most appropriate for indicating invalid arguments. PhlyRestfully uses the code to generate the httpStatus field. It uses the exception's message to set the detail field. But, the title field is set based on a variety of conditions, including the httpStatus/code, the ApiProblem class's problemStatusTitles property, and the name of the exception.

Here are my questions:
1. Is there a better way to populate the title?
2. If the general approach to titles is to remain unchanged, can ```problemStatusTitles``` be expanded to match what we find in ```Zend\Http\Response::recommendedReasonPhrases```...or at least be customizable?
3. How does one go about setting the ```describedBy``` field?
4. Should a PhlyRestfully ```Exception``` class be created/expanded that allows one to provide some/more of the API Problem fields in a more direct manner?
5. Is there a better overall approach that I could/should be taking that I've missed?

I believe that covers my questions at this point in time. Thanks in advance for any help.