(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[689],{7709:function(n,s,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/documentation/api_reference/request_object",function(){return t(6277)}])},6277:function(n,s,t){"use strict";t.r(s),t.d(s,{__N_SSG:function(){return o}});var e=t(5893),a=t(1151);function r(n){let s=Object.assign({h2:"h2",a:"a",p:"p",code:"code",pre:"pre",article:"article",ul:"ul",li:"li"},(0,a.ah)(),n.components),{Row:t,Col:r,CodeGroup:o}=s;return o||i("CodeGroup",!0),r||i("Col",!0),t||i("Row",!0),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(s.h2,{id:"request-object",children:(0,e.jsx)(s.a,{href:"#request-object",children:"Request Object"})}),"\n",(0,e.jsx)(s.p,{children:"The request object is a dataclass that contains all the information about the request. It is available in the route handler as the first argument."}),"\n",(0,e.jsxs)(t,{children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(s.p,{children:"The request object is created in Rust side but is exposed to Python as a dataclass."}),(0,e.jsxs)("ul",{children:[(0,e.jsx)("li",{children:(0,e.jsx)(s.p,{children:"Attributes:"})}),(0,e.jsx)("li",{children:(0,e.jsxs)(s.p,{children:["queries (dict[str, str]): The query parameters of the request. ",(0,e.jsx)(s.code,{children:'e.g. /user?id=123 -> {"id": "123"}'})]})}),(0,e.jsx)("li",{children:(0,e.jsxs)(s.p,{children:["headers (dict[str, str]): The headers of the request. ",(0,e.jsx)(s.code,{children:'e.g. {"Content-Type": "application/json"}'})]})}),(0,e.jsx)("li",{children:(0,e.jsxs)(s.p,{children:["params (dict[str, str]): The parameters of the request. ",(0,e.jsx)(s.code,{children:'e.g. /user/:id -> {"id": "123"}'})]})}),(0,e.jsx)("li",{children:(0,e.jsx)(s.p,{children:"body (Union[str, bytes]): The body of the request. If the request is a JSON, it will be a dict."})}),(0,e.jsx)("li",{children:(0,e.jsxs)(s.p,{children:["method (str): The method of the request. ",(0,e.jsx)(s.code,{children:"e.g. GET, POST, PUT, DELETE"})]})}),(0,e.jsx)("li",{children:(0,e.jsx)(s.p,{children:"ip_addr (Optional[str]): The IP Address of the client"})}),(0,e.jsx)("li",{children:(0,e.jsx)(s.p,{children:"identity (Optional[Identity]): The identity of the client"})})]})]}),(0,e.jsx)(r,{sticky:!0,children:(0,e.jsxs)(o,{title:"Request",tag:"GET",label:"/hello_world",children:[(0,e.jsx)(s.pre,{language:"python",code:'@dataclass\nclass Request:\n  """\n  queries: dict[str, str]\n  headers: dict[str, str]\n  path_params: dict[str, str]\n  body: Union[str, bytes]\n  method: str\n  url: Url\n  ip_addr: Optional[str]\n  identity: Optional[Identity]\n  """\n',children:(0,e.jsx)(s.code,{className:"language-python",children:'<span><span style="color: var(--shiki-token-function)">@dataclass</span></span>\n<span><span style="color: var(--shiki-token-keyword)">class</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">Request</span><span style="color: var(--shiki-color-text)">:</span></span>\n<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-comment)">&quot;&quot;&quot;</span></span>\n<span><span style="color: var(--shiki-token-comment)">  queries: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  headers: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  path_params: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  body: Union[str, bytes]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  method: str</span></span>\n<span><span style="color: var(--shiki-token-comment)">  url: Url</span></span>\n<span><span style="color: var(--shiki-token-comment)">  ip_addr: Optional[str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  identity: Optional[Identity]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  &quot;&quot;&quot;</span></span>\n<span></span>'}),title:"untyped"}),(0,e.jsx)(s.pre,{language:"python",code:'@dataclass\nclass Request:\n  """\n  queries: dict[str, str]\n  headers: dict[str, str]\n  path_params: dict[str, str]\n  body: Union[str, bytes]\n  method: str\n  url: Url\n  ip_addr: Optional[str]\n  identity: Optional[Identity]\n  """\n',children:(0,e.jsx)(s.code,{className:"language-python",children:'<span><span style="color: var(--shiki-token-function)">@dataclass</span></span>\n<span><span style="color: var(--shiki-token-keyword)">class</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">Request</span><span style="color: var(--shiki-color-text)">:</span></span>\n<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-comment)">&quot;&quot;&quot;</span></span>\n<span><span style="color: var(--shiki-token-comment)">  queries: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  headers: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  path_params: dict[str, str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  body: Union[str, bytes]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  method: str</span></span>\n<span><span style="color: var(--shiki-token-comment)">  url: Url</span></span>\n<span><span style="color: var(--shiki-token-comment)">  ip_addr: Optional[str]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  identity: Optional[Identity]</span></span>\n<span><span style="color: var(--shiki-token-comment)">  &quot;&quot;&quot;</span></span>\n<span></span>'}),title:"typed"})]})})]}),"\n",(0,e.jsxs)(s.article,{id:"whats-next",title:"What's next?",children:["\n",(0,e.jsx)(s.h2,{id:"whats-next",children:(0,e.jsx)(s.a,{href:"#whats-next",children:"What's next?"})}),"\n",(0,e.jsx)(s.p,{children:"Now, Batman wanted to understand the configuration of the Robyn server. He was then introduced to the concept of Robyn env files."}),"\n",(0,e.jsxs)(s.ul,{children:["\n",(0,e.jsx)(s.li,{children:(0,e.jsx)(s.a,{href:"/documentation/api_reference/robyn_env",children:"Robyn Env"})}),"\n"]})]})]})}var o=!0;function i(n,s){throw Error("Expected "+(s?"component":"object")+" `"+n+"` to be defined: you likely forgot to import, pass, or provide it.")}s.default=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}=Object.assign({},(0,a.ah)(),n.components);return s?(0,e.jsx)(s,Object.assign({},n,{children:(0,e.jsx)(r,n)})):r(n)}}},function(n){n.O(0,[774,888,179],function(){return n(n.s=7709)}),_N_E=n.O()}]);