Getting Started

Iris has an expressive syntax for routing which feels like home. The routing algorithm is powered by the muxie project which handles requests and matches routes faster than its alternatives like httprouter and gin or echo.

Let's get started without any hassle.

Create an empty file, let's assume its name is example.go, then open it and copy-paste the below code.

package main
import ""
func main() {
app := iris.Default()
app.Handle("GET", "/ping", func(ctx iris.Context) {
ctx.JSON(iris.Map{"message": "pong"})
// Listens and serves incoming http requests
// on http://localhost:8080.
func myMiddleware(ctx iris.Context) {
ctx.Application().Logger().Infof("Runs before %s", ctx.Path())

Start a terminal session and execute the following.

# run example.go and visit http://localhost:8080/ping on browser
$ go run example.go

Show me more!

Let's take a small overview of how easy is to get up and running.

package main
import ""
func main() {
app := iris.New()
// Load all templates from the "./views" folder
// where extension is ".html" and parse them
// using the standard `html/template` package.
app.RegisterView(iris.HTML("./views", ".html"))
// Method: GET
// Resource: http://localhost:8080
app.Get("/", func(ctx iris.Context) {
// Bind: {{.message}} with "Hello world!"
ctx.ViewData("message", "Hello world!")
// Render template file: ./views/hello.html
// Method: GET
// Resource: http://localhost:8080/user/42
// Need to use a custom regexp instead?
// Easy;
// Just mark the parameter's type to 'string'
// which accepts anything and make use of
// its `regexp` macro function, i.e:
// app.Get("/user/{id:string regexp(^[0-9]+$)}")
app.Get("/user/{id:uint64}", func(ctx iris.Context) {
userID, _ := ctx.Params().GetUint64("id")
ctx.Writef("User ID: %d", userID)
// Start the server using a network address.
<!-- file: ./views/hello.html -->
<title>Hello Page</title>
<h1>{{ .message }}</h1>
overview screen

Wanna re-start your app automatically when source code changes happens? Install the rizla tool and execute rizla main.go instead of go run main.go.

At the next section we will learn more about Routing.