Skip to content

Getting Started

Welcome to Marten! This guide will help you get up and running quickly.

What is Marten?

Marten is a minimal, elegant web framework for Go. It provides:

  • Fast routing with a radix tree router
  • Clean context with helpers for common tasks
  • Flexible middleware system
  • Route groups for organizing your API
  • Zero dependencies beyond Go's standard library

Prerequisites

  • Go 1.22 or later
  • Basic knowledge of Go

Quick Install

go get github.com/gomarten/marten

Your First App

Create a new file called main.go:

package main

import (
    "github.com/gomarten/marten"
    "github.com/gomarten/marten/middleware"
)

func main() {
    // Create a new app
    app := marten.New()

    // Add middleware
    app.Use(middleware.Logger, middleware.Recover)

    // Define routes
    app.GET("/", func(c *marten.Ctx) error {
        return c.OK(marten.M{
            "message": "Welcome to Marten!",
        })
    })

    app.GET("/hello/:name", func(c *marten.Ctx) error {
        name := c.Param("name")
        return c.OK(marten.M{
            "message": "Hello, " + name + "!",
        })
    })

    // Start the server
    app.Run(":3000")
}

Run it:

go run main.go

Test it:

curl http://localhost:3000/
# {"message":"Welcome to Marten!"}

curl http://localhost:3000/hello/World
# {"message":"Hello, World!"}

Next Steps

  • Installation


    Detailed installation instructions and requirements

    Installation

  • Quick Start


    Build a complete REST API in 5 minutes

    Quick Start

  • Project Structure


    Recommended ways to organize your Marten project

    Project Structure