Context represents the context of the current HTTP request. It holds request and response objects, path, path parameters, data and registered handler.

Hierarchy

  • Context

Indexable

[key: string]: any

Methods

  • Attachment sends a response as attachment, prompting client to save the file.

    Parameters

    • file: string
    • name: string

    Returns void

  • Bind binds path params, query params and the request body into provided type i. The default binder binds body based on Content-Type header.

    Parameters

    • i: {}

      Returns void

    • Blob sends a blob response with status code and content type.

      Parameters

      • code: number
      • contentType: string
      • b: string | number[]

      Returns void

    • Echo returns the Echo instance.

      WARNING: Remember that Echo public fields and methods are coroutine safe ONLY when you are NOT mutating them anywhere in your code after Echo server has started.

      Returns Echo

    • Error invokes the registered global HTTP error handler. Generally used by middleware. A side-effect of calling global error handler is that now Response has been committed (sent to the client) and middlewares up in chain can not change Response status code or Response body anymore.

      Avoid using this method in handlers as no middleware will be able to effectively handle errors after that. Instead of calling this method in handler return your error and let it be handled by middlewares or global error handler.

      Parameters

      • err: Error

      Returns void

    • File sends a response with the content of the file.

      Parameters

      • file: string

      Returns void

    • FileFS sends a response with the content of the file from given filesystem.

      Parameters

      • file: string
      • filesystem: FS

      Returns void

    • FormValue returns the form field value for the provided name.

      Parameters

      • name: string

      Returns string

    • FormValueDefault returns the form field value or default value for the provided name.

      Parameters

      • name: string
      • defaultValue: string

      Returns string

    • Get retrieves data from the context.

      Parameters

      • key: string

      Returns {}

      • HTML sends an HTTP response with status code.

        Parameters

        • code: number
        • html: string

        Returns void

      • HTMLBlob sends an HTTP blob response with status code.

        Parameters

        • code: number
        • b: string | number[]

        Returns void

      • Inline sends a response as inline, opening the file in the browser.

        Parameters

        • file: string
        • name: string

        Returns void

      • IsTLS returns true if HTTP connection is TLS otherwise false.

        Returns boolean

      • IsWebSocket returns true if HTTP connection is WebSocket otherwise false.

        Returns boolean

      • JSON sends a JSON response with status code.

        Parameters

        • code: number
        • i: {}

          Returns void

        • JSONBlob sends a JSON blob response with status code.

          Parameters

          • code: number
          • b: string | number[]

          Returns void

        • JSONPretty sends a pretty-print JSON with status code.

          Parameters

          • code: number
          • i: {}
            • indent: string

            Returns void

          • JSONP sends a JSONP response with status code. It uses callback to construct the JSONP payload.

            Parameters

            • code: number
            • callback: string
            • i: {}

              Returns void

            • JSONPBlob sends a JSONP blob response with status code. It uses callback to construct the JSONP payload.

              Parameters

              • code: number
              • callback: string
              • b: string | number[]

              Returns void

            • NoContent sends a response with no body and a status code.

              Parameters

              • code: number

              Returns void

            • Path returns the registered path for the handler.

              Returns string

            • PathParam returns path parameter by name.

              Parameters

              • name: string

              Returns string

            • PathParamDefault returns the path parameter or default value for the provided name.

              Notes for DefaultRouter implementation: Path parameter could be empty for cases like that:

              • route /release-:version/bin and request URL is /release-/bin
              • route /api/:version/image.jpg and request URL is /api//image.jpg but not when path parameter is last part of route path
              • route /download/file.:ext will not match request /download/file.

              Parameters

              • name: string
              • defaultValue: string

              Returns string

            • QueryParam returns the query param for the provided name.

              Parameters

              • name: string

              Returns string

            • QueryParamDefault returns the query param or default value for the provided name.

              Parameters

              • name: string
              • defaultValue: string

              Returns string

            • QueryString returns the URL query string.

              Returns string

            • RealIP returns the client's network address based on X-Forwarded-For or X-Real-IP request header. The behavior can be configured using Echo#IPExtractor.

              Returns string

            • Redirect redirects the request to a provided URL with status code.

              Parameters

              • code: number
              • url: string

              Returns void

            • Render renders a template with data and sends a text/html response with status code. Renderer must be registered using Echo.Renderer.

              Parameters

              • code: number
              • name: string
              • data: {}

                Returns void

              • RouteInfo returns current request route information. Method, Path, Name and params if they exist for matched route. In case of 404 (route not found) and 405 (method not allowed) RouteInfo returns generic struct for these cases.

                Returns RouteInfo

              • Scheme returns the HTTP protocol scheme, http or https.

                Returns string

              • Set saves data in the context.

                Parameters

                • key: string
                • val: {}

                  Returns void

                • SetCookie adds a Set-Cookie header in HTTP response.

                  Parameters

                  Returns void

                • SetPathParams sets path parameters for current request.

                  Parameters

                  Returns void

                • SetRequest sets *http.Request.

                  Parameters

                  Returns void

                • Stream sends a streaming response with status code and content type.

                  Parameters

                  • code: number
                  • contentType: string
                  • r: io.Reader

                  Returns void

                • String sends a string response with status code.

                  Parameters

                  • code: number
                  • s: string

                  Returns void

                • Validate validates provided i. It is usually called after Context#Bind(). Validator must be registered using Echo#Validator.

                  Parameters

                  • i: {}

                    Returns void

                  • XML sends an XML response with status code.

                    Parameters

                    • code: number
                    • i: {}

                      Returns void

                    • XMLBlob sends an XML blob response with status code.

                      Parameters

                      • code: number
                      • b: string | number[]

                      Returns void

                    • XMLPretty sends a pretty-print XML with status code.

                      Parameters

                      • code: number
                      • i: {}
                        • indent: string

                        Returns void

                      Generated using TypeDoc