Echo is the top-level framework instance.

Goroutine safety: Do not mutate Echo instance fields after server has started. Accessing these fields from handlers/middlewares and changing field values at the same time leads to data-races. Same rule applies to adding new routes after server has been started - Adding a route is not Goroutine safe action.

Hierarchy

  • Echo

Methods

  • AcquireContext returns an empty Context instance from the pool. You must return the context by calling ReleaseContext().

    Returns echo.Context

  • Add registers a new route for an HTTP method and path with matching handler in the router with optional route-level middleware.

    Parameters

    Returns RouteInfo

  • Any registers a new route for all HTTP methods (supported by Echo) and path with matching handler in the router with optional route-level middleware.

    Note: this method only adds specific set of supported HTTP methods as handler and is not true "catch-any-arbitrary-method" way of matching requests.

    Parameters

    Returns Routes

  • File registers a new route with path to serve a static file with optional route-level middleware. Panics on error.

    Parameters

    Returns RouteInfo

  • FileFS registers a new route with path to serve file from the provided file system.

    Parameters

    Returns RouteInfo

  • Match registers a new route for multiple HTTP methods and path with matching handler in the router with optional route-level middleware. Panics on error.

    Parameters

    Returns Routes

  • NewContext returns a new Context instance.

    Note: both request and response can be left to nil as Echo.ServeHTTP will call c.Reset(req,resp) anyway these arguments are useful when creating context for tests and cases like that.

    Parameters

    Returns echo.Context

  • Pre adds middleware to the chain which is run before router tries to find matching route. Meaning middleware is executed even for 404 (not found) cases.

    Parameters

    Returns void

  • ReleaseContext returns the Context instance back to the pool. You must call it after AcquireContext().

    Parameters

    Returns void

  • ResetRouterCreator resets callback for creating new router instances. Note: current (default) router is immediately replaced with router created with creator func and vhost routers are cleared.

    Parameters

    Returns void

  • RouteNotFound registers a special-case route which is executed when no other route is found (i.e. HTTP 404 cases) for current request URL. Path supports static and named/any parameters just like other http method is defined. Generally path is ended with wildcard/match-any character (/*, /download/* etc).

    Example: e.RouteNotFound("/*", func(c echo.Context) error { return c.NoContent(http.StatusNotFound) })

    Parameters

    Returns RouteInfo

  • RouterFor returns Router for given host. When host is left empty the default router is returned.

    Parameters

    • host: string

    Returns [Router, boolean]

  • Start stars HTTP server on given address with Echo as a handler serving requests. The server can be shutdown by sending os.Interrupt signal with ctrl+c.

    Note: this method is created for use in examples/demos and is deliberately simple without providing configuration options.

    In need of customization use:

     sc := echo.StartConfig{Address: ":8080"}
    if err := sc.Start(e); err != http.ErrServerClosed {
    log.Fatal(err)
    }

    // or standard library http.Server

     s := http.Server{Addr: ":8080", Handler: e}
    if err := s.ListenAndServe(); err != http.ErrServerClosed {
    log.Fatal(err)
    }

    Parameters

    • address: string

    Returns void

  • Static registers a new route with path prefix to serve static files from the provided root directory.

    Parameters

    • pathPrefix: string
    • fsRoot: string

    Returns RouteInfo

  • StaticFS registers a new route with path prefix to serve static files from the provided file system.

    When dealing with embed.FS use fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary prefix for directory path. This is necessary as //go:embed assets/imagesembeds files with paths includingassets/images` as their prefix.

    Parameters

    • pathPrefix: string
    • filesystem: FS

    Returns RouteInfo

  • Use adds middleware to the chain which is run after router has found matching route and before route/request handler method is executed.

    Parameters

    Returns void

Properties

binder: Binder
debug: boolean
filesystem: FS

Filesystem is file system used by Static and File handlers to access files. Defaults to os.DirFS(".")

When dealing with embed.FS use fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary prefix for directory path. This is necessary as //go:embed assets/imagesembeds files with paths includingassets/images` as their prefix.

httpErrorHandler: HTTPErrorHandler
ipExtractor: IPExtractor
jsonSerializer: JSONSerializer
logger: echo.Logger
newContextFunc: ((e, pathParamAllocSize) => ServableContext)

Type declaration

    • (e, pathParamAllocSize): ServableContext
    • NewContextFunc allows using custom context implementations, instead of default *echo.context

      Parameters

      • e: Echo
      • pathParamAllocSize: number

      Returns ServableContext

onAddRoute: ((host, route) => void)

Type declaration

    • (host, route): void
    • OnAddRoute is called when Echo adds new route to specific host router. Handler is called for every router and before route is added to the host router.

      Parameters

      Returns void

renderer: echo.Renderer
validator: Validator

Generated using TypeDoc