Echo: Access to http.Request/Response from echo.Context?

Created on 15 Mar 2016  路  3Comments  路  Source: labstack/echo

I want to access the other url.URL fields like .RawQuery from v2 echo.Context.

func Index(c echo.Context) error {
  log.Println(c.Request().URL().RawQuery)
}

I also would like to have access to other http.Request and http.Response methods not available through context yet.
Thanks!

question

Most helpful comment

Echo v2 abstracts underlying HTTP server so you don't have direct access to internal objects like request, response or url. This is done to make Echo compatible with many HTTP servers.

We try to expose most generic methods via engine.* interfaces but if you don't find them you can get get the real objects like below (standard HTTP server):

// `*http.Request`
c.Request().(*standard.Request).Request

// `*http.URL`
c.Request().(*standard.URL).URL

// `http.Header`
c.Request().(*standard.Header).Header

// `http.ResponseWriter`
c.Response().(*standard.Response).ResponseWriter

// `http.Header`
c.Response().(*standard.Header).Header

I will look into exposing new API to fetch query string.

All 3 comments

Echo v2 abstracts underlying HTTP server so you don't have direct access to internal objects like request, response or url. This is done to make Echo compatible with many HTTP servers.

We try to expose most generic methods via engine.* interfaces but if you don't find them you can get get the real objects like below (standard HTTP server):

// `*http.Request`
c.Request().(*standard.Request).Request

// `*http.URL`
c.Request().(*standard.URL).URL

// `http.Header`
c.Request().(*standard.Header).Header

// `http.ResponseWriter`
c.Response().(*standard.Response).ResponseWriter

// `http.Header`
c.Response().(*standard.Header).Header

I will look into exposing new API to fetch query string.

API Request#QueryString() exposed.

mark as ResponseWriter

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ellisonleao picture ellisonleao  路  3Comments

syntaqx picture syntaqx  路  3Comments

leoycx picture leoycx  路  4Comments

asdine picture asdine  路  3Comments

danieldaeschle picture danieldaeschle  路  3Comments