Go Fiber HTTP Methods
A list of HTTP methods for the Fiber API
By Keith Thomson โข 2 min read โข golang,fiber,http
Fiber Go ๐ฎ Request Methods
These are how you access client request data.
๐General Request Info
- ctx.Method() []byte โ HTTP method (GET, POST, etc.)
- ctx.Path() []byte โ Request path (e.g. /users/123)
- ctx.RequestURI() []byte โ Full request URI
- ctx.Host() []byte โ Host header
- ctx.RemoteAddr() net.Addr โ Client IP + port
- ctx.RemoteIP() net.IP โ Just the client IP
โญQuery & Params
- ctx.QueryArgs() *fasthttp.Args โ All query string args (?foo=bar)
- ctx.QueryArgs().Peek("foo") โ []byte value for foo
- ctx.UserValue("param") โ Path parameter (if you use a router like fasthttprouter)
โญHeaders
- ctx.Request.Header (struct with methods):
- .Peek("Header-Name") []byte
- .ContentType() []byte
- .UserAgent() []byte
- .Referer() []byte
- .Cookie("name") []byte
โญBody
- ctx.PostBody() []byte โ Raw body
- ctx.FormValue("key") []byte โ Form field (works with application/x-www-form-urlencoded)
- ctx.MultipartForm() (*multipart.Form, error) โ File uploads / multipart form
- ctx.IsBodyStream() โ Whether body is a streaming input
Response โ w methods
These control what gets sent back.
๐Headers & Status
- ctx.SetStatusCode(code int) โ Set status (200, 404, etc.)
- ctx.Response.Header.Set("Header", "value")
- ctx.Response.Header.SetContentType("application/json")
- ctx.Response.Header.SetCanonical([]byte("X-Header"), []byte("val"))
- ctx.Response.Header.SetCookie(cookie *fasthttp.Cookie)
๐ผ Body Writing
- ctx.SetBody([]byte)
- ctx.SetBodyString(string)
- ctx.SetBodyStream(r io.Reader, size int)
- ctx.Write([]byte) โ Writes to response (append-style)
- ctx.WriteString(string)
- ctx.SendFile("path/to/file") โ Serve static files
๐ Redirects
- ctx.Redirect(uri string, statusCode int)
- ctx.RedirectBytes(uri []byte, statusCode int)
โ๏ธ Utility & Middleware Helpers
- ctx.Next() โ (if using middleware chains, e.g. in fasthttprouter)
- ctx.Done() โ Context cancellation
- ctx.Time() โ Request start timestamp
- ctx.Response.Reset() โ Clear response
- ctx.Request.Reset() โ Clear request
โ Quick Example
Simple API using Go with Fiber
func main() {
app := fiber.New()
api := app.Group("/api", middleware) // /api
v1 := api.Group("/v1", middleware) // /api/v1
v1.Get("/list", handler) // /api/v1/list
v1.Get("/user", handler) // /api/v1/user
v2 := api.Group("/v2", middleware) // /api/v2
v2.Get("/list", handler) // /api/v2/list
v2.Get("/user", handler) // /api/v2/user
log.Fatal(app.Listen(":3000"))
}