From c1ada9298a683641f26773f9fefdae0aa70f8e71 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 16 Aug 2019 18:39:35 +0300 Subject: [PATCH] doc problem xml --- Routing-error-handlers.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Routing-error-handlers.md b/Routing-error-handlers.md index 3afa691..bd1cc37 100644 --- a/Routing-error-handlers.md +++ b/Routing-error-handlers.md @@ -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 + + https://host.domain/product-error + 400 + Product validation problem + problem error details + product name + +``` + Full example can be found at [_examples/routing/http-errors](https://github.com/kataras/iris/blob/master/_examples/routing/http-errors/main.go).