From 1389bfb1d35481b7769fb92a8ab18771df8e1bca Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Mon, 12 Dec 2016 16:04:25 -0200 Subject: [PATCH] add special handler docs (#408) --- docs/operating/extending.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/operating/extending.md b/docs/operating/extending.md index dcdbf9db6..c46fd92b1 100644 --- a/docs/operating/extending.md +++ b/docs/operating/extending.md @@ -71,4 +71,35 @@ _Triggers before and after every app deletion that happens in the API_ Triggered during requests to the following routes: -- DELETE /v1/apps/app \ No newline at end of file +- DELETE /v1/apps/app + +## Special Handlers + +To understand how **Special Handlers** works you need to understand what are **Special Routes**. + +**Special Routes** are routes that doesn't match any other API route. + +With **Special Handlers** you can change the behavior of special routes in order to define which function is going to be executed. + +For example, let's use special handlers to define `mydomain` as the `appname` for any request for `mydomain.com`. + +``` +type SpecialHandler struct{} + +func (h *SpecialHandler) Handle(c ifaces.HandlerContext) error { + host := c.Request().Host + if host == "mydomain.com" { + c.Set("app", "mydomain") + } +} + +func main () { + sh := &SpecialHandler{} + + srv := server.New(/* Here all required parameters to initialize the server */) + srv.AddSpecialHandler(sh) + srv.Run() +} +``` + +With the code above, a request to `http://mydomain.com/hello` will trigger the function `/mydomain/hello` \ No newline at end of file