"use strict";(self.webpackChunkgoffee_site=self.webpackChunkgoffee_site||[]).push([[6509],{7183:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>l,toc:()=>d});var s=t(4848),r=t(8453);const o={title:"Response"},c=void 0,l={id:"response",title:"Response",description:"Below are the different types of responses you can return to the user",source:"@site/docs/response.md",sourceDirName:".",slug:"/response",permalink:"/goffee/docs/response",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{title:"Response"},sidebar:"docsSidebar",previous:{title:"Request",permalink:"/goffee/docs/request"},next:{title:"Log system",permalink:"/goffee/docs/logsystem"}},a={},d=[{value:"Return JSON",id:"return-json",level:2},{value:"Return HTML",id:"return-html",level:2},{value:"Return Template",id:"return-template",level:2},{value:"Return Text",id:"return-text",level:2},{value:"Return Any response",id:"return-any-response",level:2},{value:"Set response headers",id:"set-response-headers",level:2},{value:"Set response content type",id:"set-response-content-type",level:2},{value:"Set response status code",id:"set-response-status-code",level:2}];function u(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Below are the different types of responses you can return to the user"}),"\n",(0,s.jsx)(n.h2,{id:"return-json",children:"Return JSON"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func SomeHandler(c *core.Context) {\n    return c.Response.Json(myJson)\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"return-html",children:"Return HTML"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func SomeHandler(c *core.Context) {\n    return c.Response.HTML(myHTML)\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"return-template",children:"Return Template"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'func SomeHandler(c *core.Context) {\n    return c.Response.Template("mytemplate.html", tmplData)\n}\n'})}),"\n",(0,s.jsx)(n.h2,{id:"return-text",children:"Return Text"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func SomeHandler(c *core.Context) {\n    return c.Response.Text(myText)\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"return-any-response",children:"Return Any response"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func SomeHandler(c *core.Context) {\n    return c.Response.Any(anyResponse)\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"set-response-headers",children:"Set response headers"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'func SomeHandler(c *core.Context) {\n    return c.Response.SetHeader("key", "value").Json(myJson)\n}\n'})}),"\n",(0,s.jsx)(n.h2,{id:"set-response-content-type",children:"Set response content type"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'func SomeHandler(c *core.Context) {\n    return c.Response.SetContentType("application/json").any(myJson)\n}\n'})}),"\n",(0,s.jsx)(n.h2,{id:"set-response-status-code",children:"Set response status code"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func SomeHandler(c *core.Context) {\n    return c.Response.SetStatusCode(400).Json(myJson)\n}\n"})})]})}function p(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(u,{...e})}):u(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>l});var s=t(6540);const r={},o=s.createContext(r);function c(e){const n=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);