Skip to content

HTTP package guide

The gox/http package mirrors Express.js patterns: apps, routers, middleware, JSON handlers, and built-in security helpers.

Core routing

Expressgox
express()http.New()
app.get('/path', handler)app.Get("/path", handler)
res.json(data)return c.JSON(200, data)
req.bodyc.BindJSON(&v)
req.params.idc.Param("id")

See: http.New, http.Ctx.JSON

Middleware

npmgox
corshttp.CORS
helmethttp.Security
morganhttp.Logger
error handlerReturn error from handlers; use gox/err for status codes

Advanced features

npmgox
multerhttp.ParseMultipart, http.SaveUploadedFile
express-sessionhttp.SessionMiddleware, http.MemoryStore
Server-Sent Eventshttp.SSE, http.SSEHandler
express-rate-limithttp.RateLimit
WebSocket upgradehttp.HandleWS, gox/ws

Example

go
import (
    goxerr "github.com/sahilkhaire/gox/err"
    goxhttp "github.com/sahilkhaire/gox/http"
)

app := goxhttp.New()
app.Use(goxhttp.Logger(), goxhttp.Recover(), goxhttp.Security())

app.Get("/health", func(c *goxhttp.Ctx) error {
    return c.JSON(200, map[string]string{"status": "ok"})
})

app.Post("/users", func(c *goxhttp.Ctx) error {
    var u struct{ Name string `json:"name"` }
    if err := c.BindJSON(&u); err != nil {
        return goxerr.BadRequest("invalid json")
    }
    return c.JSON(201, u)
})

See the Express migration guide for a full side-by-side walkthrough.

MIT Licensed · Built for Node.js developers moving to Go