doc problem xml

Gerasimos (Makis) Maropoulos 2019-08-16 18:39:35 +03:00
parent cf39e57b04
commit c1ada9298a
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7

@ -44,8 +44,10 @@ func index(ctx iris.Context) {
Iris has builtin support for the [Problem Details for HTTP APIs](https://tools.ietf.org/html/rfc7807).
The `Context.Problem` method sends a response like `Context.JSON` does but with indent of " " and
a content type of "application/problem+json" instead.
The `Context.Problem` writes a JSON or XML problem response. Behaves exactly like `Context.JSON` but with default ProblemOptions.JSON indent of " " and a response content type of "application/problem+json" instead.
Use the options.RenderXML and XML fields to change this behavior and
send a response of content type "application/problem+xml" instead.
```go
func newProductProblem(productName, detail string) iris.Problem {
@ -72,6 +74,10 @@ func fireProblem(ctx iris.Context) {
JSON: iris.JSON{
Indent: " ",
},
// OR
// Render as XML:
// RenderXML: true,
// XML: iris.XML{Indent: " "},
// Sets the "Retry-After" response header.
//
// Can accept:
@ -105,4 +111,18 @@ func fireProblem(ctx iris.Context) {
}
```
When `RenderXML` is set to `true` then the response will look be rendered as XML instead.
**Outputs "application/problem+xml"**
```xml
<Problem>
<Type>https://host.domain/product-error</Type>
<Status>400</Status>
<Title>Product validation problem</Title>
<Detail>problem error details</Detail>
<ProductName>product name</ProductName>
</Problem>
```
Full example can be found at [_examples/routing/http-errors](https://github.com/kataras/iris/blob/master/_examples/routing/http-errors/main.go).