> For the complete documentation index, see [llms.txt](https://alexisvisco.gitbook.io/kcd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alexisvisco.gitbook.io/kcd/handler/how-to-use-kcd.handler.md).

# How to use kcd.Handler

The `kcd.Handler` takes a function (which is your handler) and a default status code.&#x20;

It returns a normal standard `http.HandlerFunc`so you can use it with classic routers.&#x20;

```go
r.Get("/superman", kcd.Handler(YourMagicHandler, http.StatusOK))
```

`YourMagicHandler` is a handler of your application, this is where the magic happens!

### Construct your handler

#### Function parameters accepted

* context.Context
* http.ResponseWriter
* \*http.Request
* Your custom input struct as a pointer

#### &#x20;Function return

* Your custom output (could be either a pointer or non-pointer type)
* error

#### Additional information

The minimal signature of your function looks like this:

```go
func MagicHandler() error
```

The maximal signature of your function may look like this:

```go
func MagicHandler(ctx context.Context, res http.ResponseWriter, req *http.Request, in *MyInput) (out MyOutpput, err error)
```

* All inputs parameters can be omitted
* The order of inputs parameters is not important
* The Input (represented as `in *MyInput`) must be a pointer
* The order of the return must be preserved with the error as the last parameter

#### Exception

You can use the standard http handler.

{% content-ref url="/pages/-MZYDyCDurJjiOlfRMHY" %}
[Compatible with the standard library](/kcd/compatible-with/compatible-with-the-standard-library.md)
{% endcontent-ref %}
