Add registers a new route for an HTTP method and path with matching handler in the router with optional route-level middleware.
Rest
...middleware: MiddlewareFunc[]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.
Rest
...middleware: MiddlewareFunc[]CONNECT registers a new CONNECT route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]DELETE registers a new DELETE route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]File registers a new route with path to serve a static file with optional route-level middleware. Panics on error.
Rest
...middleware: MiddlewareFunc[]FileFS registers a new route with path to serve file from the provided file system.
Rest
...m: MiddlewareFunc[]GET registers a new GET route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]Group creates a new router group with prefix and optional group-level middleware.
Rest
...m: MiddlewareFunc[]HEAD registers a new HEAD route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]Host creates a new router group for the provided host and optional host-level middleware.
Rest
...m: MiddlewareFunc[]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.
Rest
...middleware: MiddlewareFunc[]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.
OPTIONS registers a new OPTIONS route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]PATCH registers a new PATCH route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]POST registers a new POST route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]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.
Rest
...middleware: MiddlewareFunc[]PUT registers a new PUT route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]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) })
Rest
...m: MiddlewareFunc[]Routers returns the new map of host => router.
ServeHTTP implements http.Handler
interface, which serves HTTP requests.
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)
}
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 including
assets/images` as their prefix.
TRACE registers a new TRACE route for a path with matching handler in the router with optional route-level middleware. Panics on error.
Rest
...m: MiddlewareFunc[]Use adds middleware to the chain which is run after router has found matching route and before route/request handler method is executed.
Rest
...middleware: MiddlewareFunc[]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 including
assets/images` as their prefix.
NewContextFunc allows using custom context implementations, instead of default *echo.context
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.
Generated using TypeDoc
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.