Skip to content

API Reference

Complete API documentation for Marten.

Core Types

Type Description
App Main application instance
Ctx Request context with helpers
Router HTTP routing
Middleware Built-in middleware

Quick Reference

Creating an App

app := marten.New()
app.Run(":8080")

Registering Routes

app.GET("/path", handler)
app.POST("/path", handler)
app.PUT("/path/:id", handler)
app.DELETE("/path/:id", handler)

Handler Signature

func handler(c *marten.Ctx) error {
    return c.OK(data)
}

Middleware Signature

func middleware(next marten.Handler) marten.Handler {
    return func(c *marten.Ctx) error {
        // before
        err := next(c)
        // after
        return err
    }
}

Convenience Types

// Map shorthand
marten.M{"key": "value"}

// Error response
marten.E("error message")
// Returns: {"error": "error message"}