mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 18:56:29 +01:00
doc problem xml
parent
cf39e57b04
commit
c1ada9298a
|
@ -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).
|
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
|
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.
|
||||||
a 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
|
```go
|
||||||
func newProductProblem(productName, detail string) iris.Problem {
|
func newProductProblem(productName, detail string) iris.Problem {
|
||||||
|
@ -72,6 +74,10 @@ func fireProblem(ctx iris.Context) {
|
||||||
JSON: iris.JSON{
|
JSON: iris.JSON{
|
||||||
Indent: " ",
|
Indent: " ",
|
||||||
},
|
},
|
||||||
|
// OR
|
||||||
|
// Render as XML:
|
||||||
|
// RenderXML: true,
|
||||||
|
// XML: iris.XML{Indent: " "},
|
||||||
// Sets the "Retry-After" response header.
|
// Sets the "Retry-After" response header.
|
||||||
//
|
//
|
||||||
// Can accept:
|
// 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).
|
Full example can be found at [_examples/routing/http-errors](https://github.com/kataras/iris/blob/master/_examples/routing/http-errors/main.go).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user