description
Fiber represents the fiber package where you start to create an instance.

📦 Fiber

New

This method creates a new App named instance. You can pass optional settings when creating a new instance

  1. func New(config ...Config) *App
  1. // Default config
  2. app := fiber.New()
  3. // ...

Config

You can pass an optional Config when creating a new Fiber instance.

  1. // Custom config
  2. app := fiber.New(fiber.Config{
  3. Prefork: true,
  4. CaseSensitive: true,
  5. StrictRouting: true,
  6. ServerHeader: "Fiber",
  7. })
  8. // ...

Config fields

PropertyTypeDescriptionDefault
PreforkboolEnables use of theSO_REUSEPORTsocket option. This will spawn multiple Go processes listening on the same port. learn more about socket sharding.false
ServerHeaderstringEnables the Server HTTP header with the given value.“”
StrictRoutingboolWhen enabled, the router treats /foo and /foo/ as different. Otherwise, the router treats /foo and /foo/ as the same.false
CaseSensitiveboolWhen enabled, /Foo and /foo are different routes. When disabled, /Fooand /foo are treated the same.false
ImmutableboolWhen enabled, all values returned by context methods are immutable. By default, they are valid until you return from the handler; see issue #185.false
UnescapePathboolConverts all encoded characters in the route back before setting the path for the context, so that the routing can also work with URL encoded special charactersfalse
ETagboolEnable or disable ETag header generation, since both weak and strong etags are generated using the same hashing method (CRC-32). Weak ETags are the default when enabled.false
BodyLimitintSets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends 413 - Request Entity Too Large response.4 1024 1024
ConcurrencyintMaximum number of concurrent connections.256 1024
ViewsViewsViews is the interface that wraps the Render function. See our Template Middleware for supported engines.nil
ReadTimeouttime.DurationThe amount of time allowed to read the full request, including the body. The default timeout is unlimited.nil
WriteTimeouttime.DurationThe maximum duration before timing out writes of the response. The default timeout is unlimited.nil
IdleTimeouttime.DurationThe maximum amount of time to wait for the next request when keep-alive is enabled. If IdleTimeout is zero, the value of ReadTimeout is used.nil
ReadBufferSizeintper-connection buffer size for requests’ reading. This also limits the maximum header size. Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies).4096
WriteBufferSizeintPer-connection buffer size for responses’ writing.4096
CompressedFileSuffixstringAdds a suffix to the original file name and tries saving the resulting compressed file under the new file name.“.fiber.gz”
ProxyHeaderstringThis will enable c.IP() to return the value of the given header key. By default c.IP() will return the Remote IP from the TCP connection, this property can be useful if you are behind a load balancer e.g. X-Forwarded-.“”
GETOnlyboolRejects all non-GET requests if set to true. This option is useful as anti-DoS protection for servers accepting only GET requests. The request size is limited by ReadBufferSize if GETOnly is set.false
ErrorHandlerErrorHandlerErrorHandler is executed when an error is returned from fiber.Handler.DefaultErrorHandler
DisableKeepaliveboolDisable keep-alive connections, the server will close incoming connections after sending the first response to clientfalse
DisableDefaultDateboolWhen set to true causes the default date header to be excluded from the response.false
DisableDefaultContentTypeboolWhen set to true, causes the default Content-Type header to be excluded from the Response.false
DisableHeaderNormalizingboolBy default all header names are normalized: conteNT-tYPE -> Content-Typefalse
DisableStartupMessageboolWhen set to true, it will not print out debug informationfalse

NewError

NewError creates a new HTTPError instance with an optional message

  1. func NewError(code int, message ...string) *Error
  1. app.Get(func(c *fiber.Ctx) error {
  2. return fiber.NewError(782, "Custom error message")
  3. })

IsChild

IsChild determines if the current process is a result of Prefork

  1. func IsChild() bool
  1. // Prefork will spawn child processes
  2. app := fiber.New(fiber.Config{
  3. Prefork: true,
  4. })
  5. if !fiber.IsChild() {
  6. fmt.Println("I'm the parent process")
  7. } else {
  8. fmt.Println("I'm a child process")
  9. }
  10. // ...