{"action":"created","issue":{"url":"https://api.github.com/repos/labstack/echo/issues/21","labels_url":"https://api.github.com/repos/labstack/echo/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/labstack/echo/issues/21/comments","events_url":"https://api.github.com/repos/labstack/echo/issues/21/events","html_url":"https://github.com/labstack/echo/issues/21","id":66285929,"number":21,"title":"support for context.Render","user":{"login":"prabirshrestha","id":287744,"avatar_url":"https://avatars.githubusercontent.com/u/287744?v=3","gravatar_id":"","url":"https://api.github.com/users/prabirshrestha","html_url":"https://github.com/prabirshrestha","followers_url":"https://api.github.com/users/prabirshrestha/followers","following_url":"https://api.github.com/users/prabirshrestha/following{/other_user}","gists_url":"https://api.github.com/users/prabirshrestha/gists{/gist_id}","starred_url":"https://api.github.com/users/prabirshrestha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prabirshrestha/subscriptions","organizations_url":"https://api.github.com/users/prabirshrestha/orgs","repos_url":"https://api.github.com/users/prabirshrestha/repos","events_url":"https://api.github.com/users/prabirshrestha/events{/privacy}","received_events_url":"https://api.github.com/users/prabirshrestha/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/labstack/echo/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-04-04T07:23:38Z","updated_at":"2015-04-06T05:18:06Z","closed_at":null,"body":"Would be awesome if there was a `Render` function in context similar to rendering `JSON`.\r\n\r\nHaving this `RendererFunc` interface would allow to use any renderer. Would also be good to have `html/template` as a default Render. This is similar to how `http.Handler and http.HandlerFunc` is implemented.\r\n\r\n```go\r\ntype Renderer interface {\r\n    Render(w http.ResponseWriter, r *http.Request, status int, name string, data interface{})\r\n}\r\n\r\ntype RendererFunc (w http.ResponseWriter, r *http.Request, status int, name string, data interface{})\r\n\r\nfunc (f RendererFunc) Render(w http.ResponseWriter, r *http.Request, status int, name string, data interface{})\r\n```\r\n\r\ngin use `... interface{}` for `data`. Also should we also pass `*http.Request` to `Render` so that it can support content negotiation? If we pass request as `nil` then we can tell the render to not use content negotiation. Not sure if this is too much of magic. I think content negotiation should be a separate topic.\r\n\r\nHere is sample api that could be possible to use. Thoughts?\r\n\r\n```go\r\nvar e := echo.New()\r\ne.Get(\"/\", func (c *e.Context) {\r\n    c.Render(http.StatusOK, \"home\", nil)\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/labstack/echo/issues/comments/89923323","html_url":"https://github.com/labstack/echo/issues/21#issuecomment-89923323","issue_url":"https://api.github.com/repos/labstack/echo/issues/21","id":89923323,"user":{"login":"prabirshrestha","id":287744,"avatar_url":"https://avatars.githubusercontent.com/u/287744?v=3","gravatar_id":"","url":"https://api.github.com/users/prabirshrestha","html_url":"https://github.com/prabirshrestha","followers_url":"https://api.github.com/users/prabirshrestha/followers","following_url":"https://api.github.com/users/prabirshrestha/following{/other_user}","gists_url":"https://api.github.com/users/prabirshrestha/gists{/gist_id}","starred_url":"https://api.github.com/users/prabirshrestha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prabirshrestha/subscriptions","organizations_url":"https://api.github.com/users/prabirshrestha/orgs","repos_url":"https://api.github.com/users/prabirshrestha/repos","events_url":"https://api.github.com/users/prabirshrestha/events{/privacy}","received_events_url":"https://api.github.com/users/prabirshrestha/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T05:18:06Z","updated_at":"2015-04-06T05:18:06Z","body":"That is where the `req *http.Request` parameter comes in. The `RenderFunc` can look at the headers and do the negotiation. But I think this is a bad idea.\r\n\r\nI was thinking that `RenderFunc` should only render html style contents and not json, xml, protobuf. That should be a different api. Most likely `NegotiateFunc` and `c.Negotiate`\r\n\r\nThe reason is the difference in api. Notice that render takes the name while Negotiate doesn't. (Also I need to play more with the negotiate api to make it better)\r\n\r\n```go\r\nc.Render(200, \"doc.md\", &model{}l)\r\nc.Negotiate(200, &model{})\r\n```\r\n\r\nSome references:\r\n\r\nhttps://github.com/gin-gonic/gin/issues/59\r\nhttps://github.com/gohttp/response/pull/4\r\nhttps://github.com/NancyFx/Nancy/wiki/Content-Negotiation"}}