# Routing

## Routing

```go
app := slide.InitServer(&config)
app.Get("/", func(ctx *slide.Ctx) error {
	return ctx.Send(http.StatusOK, "Hello, World")
})
app.Post("/", func(ctx *slide.Ctx) error {
	return ctx.Send(http.StatusOK, "Hello, World")
})
app.Put("/", func(ctx *slide.Ctx) error {
	return ctx.Send(http.StatusOK, "Hello, World")
})
app.Delete("/", func(ctx *slide.Ctx) error {
	return ctx.Send(http.StatusOK, "Hello, World")
})
```

## Grouping

Slide Supports grouping your routes

```go
auth := app.Group("/auth")
// this becomes /auth/login
auth.Get("/login", func(ctx *slide.Ctx) error {
	return ctx.Send(http.StatusOK, "Hello, World")
})
```

## Path Param <a href="#path-param" id="path-param"></a>

For all wild card path param we use following regex

```go
[a-zA-Z0-9_-]*
```

```go
app.Get("/:name", func(ctx *slide.Ctx) error {
		name := ctx.GetParam("name")
		return ctx.Send(http.StatusOK, fmt.Sprintf("hello, %s", name))
})
```

## Query Param <a href="#query-param" id="query-param"></a>

```go
//	returns value of a single query Param
//
//	route path /hello?key=test&value=bbp
//
//	keyValue = GetQueryParam(key)
//
//	keyValue = test

app.Get("/hello", func(ctx *slide.Ctx) error {
	params := ctx.GetQueryParams()
	return ctx.JSON(http.StatusOK, params)
})

//	returns map of query Params
//
//	route path /hello?key=test&value=bbp
//
//	returns {key : test, value : bbp}

app.Get("/hello/single", func(ctx *slide.Ctx) error {
	params := ctx.GetQueryParam("key")
	return ctx.Send(http.StatusOK, fmt.Sprintf("key is %s", params))
})
```

## Redirect

```go
// redirect to new url
app.Get("/redirect", func(ctx *slide.Ctx) error {
	return ctx.Redirect(http.StatusTemporaryRedirect, "http://localhost:3000/static")
})
```

## Custom Routes <a href="#custom-routes" id="custom-routes"></a>

**404 Handler**

```go
app.HandleNotFound(func(ctx *slide.Ctx) error {
    return ctx.JSON(http.StatusNotFound, "check url")
})
```

**Error Handler**

```go
app.HandleErrors(func(ctx *slide.Ctx, err error) error {
    return ctx.Send(http.StatusInternalServerError, err.Error())
})
```
