Commit 0f19a65d authored by dennisjenkins75's avatar dennisjenkins75

deploy: c7313b97

parent 27813cee
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[918],{3852:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return B}});var n=a(7294),l=a(6742),r=a(4973);var i=function(e){var t=e.metadata;return n.createElement("nav",{className:"pagination-nav","aria-label":(0,r.I)({id:"theme.docs.paginator.navAriaLabel",message:"Docs pages navigation",description:"The ARIA label for the docs pagination"})},n.createElement("div",{className:"pagination-nav__item"},t.previous&&n.createElement(l.Z,{className:"pagination-nav__link",to:t.previous.permalink},n.createElement("div",{className:"pagination-nav__sublabel"},n.createElement(r.Z,{id:"theme.docs.paginator.previous",description:"The label used to navigate to the previous doc"},"Previous")),n.createElement("div",{className:"pagination-nav__label"},"\xab ",t.previous.title))),n.createElement("div",{className:"pagination-nav__item pagination-nav__item--next"},t.next&&n.createElement(l.Z,{className:"pagination-nav__link",to:t.next.permalink},n.createElement("div",{className:"pagination-nav__sublabel"},n.createElement(r.Z,{id:"theme.docs.paginator.next",description:"The label used to navigate to the next doc"},"Next")),n.createElement("div",{className:"pagination-nav__label"},t.next.title," \xbb"))))},s=a(2263),o=a(907),c=a(6700);function d(e){var t=e.siteTitle,a=e.versionLabel;return n.createElement(r.Z,{id:"theme.docs.versions.unreleasedVersionLabel",description:"The label used to tell the user that he's browsing an unreleased doc version",values:{siteTitle:t,versionLabel:n.createElement("strong",null,a)}},"This is unreleased documentation for {siteTitle} {versionLabel} version.")}function m(e){var t=e.siteTitle,a=e.versionLabel;return n.createElement(r.Z,{id:"theme.docs.versions.unmaintainedVersionLabel",description:"The label used to tell the user that he's browsing an unmaintained doc version",values:{siteTitle:t,versionLabel:n.createElement("strong",null,a)}},"This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.")}function u(e){var t=e.versionLabel,a=e.to,i=e.onClick;return n.createElement(r.Z,{id:"theme.docs.versions.latestVersionSuggestionLabel",description:"The label userd to tell the user that he's browsing an unmaintained doc version",values:{versionLabel:t,latestVersionLink:n.createElement("strong",null,n.createElement(l.Z,{to:a,onClick:i},n.createElement(r.Z,{id:"theme.docs.versions.latestVersionLinkLabel",description:"The label used for the latest version suggestion link label"},"latest version")))}},"For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).")}var v=function(){var e=(0,s.default)().siteConfig.title,t=(0,o.useActivePlugin)({failfast:!0}).pluginId,a=(0,c.J)(t).savePreferredVersionName,l=(0,o.useActiveVersion)(t),r=(0,o.useDocVersionSuggestions)(t),i=r.latestDocSuggestion,v=r.latestVersionSuggestion;if(!v)return n.createElement(n.Fragment,null);var p,h=null!=i?i:(p=v).docs.find((function(e){return e.id===p.mainDocId}));return n.createElement("div",{className:"alert alert--warning margin-bottom--md",role:"alert"},n.createElement("div",null,"current"===l.name?n.createElement(d,{siteTitle:e,versionLabel:l.label}):n.createElement(m,{siteTitle:e,versionLabel:l.label})),n.createElement("div",{className:"margin-top--md"},n.createElement(u,{versionLabel:v.label,to:h.path,onClick:function(){return a(v.name)}})))},p=a(1217),h="lastUpdatedDate_1WI_";function E(e){var t=e.lastUpdatedAt,a=e.formattedLastUpdatedAt;return n.createElement(r.Z,{id:"theme.lastUpdated.atDate",description:"The words used to describe on which date a page has been last updated",values:{date:n.createElement("time",{dateTime:new Date(1e3*t).toISOString(),className:h},a)}}," on {date}")}function g(e){var t=e.lastUpdatedBy;return n.createElement(r.Z,{id:"theme.lastUpdated.byUser",description:"The words used to describe by who the page has been last updated",values:{user:n.createElement("strong",null,t)}}," by {user}")}function f(e){var t=e.lastUpdatedAt,a=e.formattedLastUpdatedAt,l=e.lastUpdatedBy;return n.createElement("div",{className:"col text--right"},n.createElement("em",null,n.createElement("small",null,n.createElement(r.Z,{id:"theme.lastUpdated.lastUpdatedAtBy",description:"The sentence used to display when a page has been last updated, and by who",values:{atDate:t&&a?n.createElement(E,{lastUpdatedAt:t,formattedLastUpdatedAt:a}):"",byUser:l?n.createElement(g,{lastUpdatedBy:l}):""}},"Last updated{atDate}{byUser}"),!1)))}var b=a(6010);var _=function(e,t,a){var l=(0,n.useState)(void 0),r=l[0],i=l[1];(0,n.useEffect)((function(){function n(){var n=function(){var e=Array.from(document.getElementsByClassName("anchor")),t=e.find((function(e){return e.getBoundingClientRect().top>=a}));if(t){if(t.getBoundingClientRect().top>=a){var n=e[e.indexOf(t)-1];return null!=n?n:t}return t}return e[e.length-1]}();if(n)for(var l=0,s=!1,o=document.getElementsByClassName(e);l<o.length&&!s;){var c=o[l],d=c.href,m=decodeURIComponent(d.substring(d.indexOf("#")+1));n.id===m&&(r&&r.classList.remove(t),c.classList.add(t),i(c),s=!0),l+=1}}return document.addEventListener("scroll",n),document.addEventListener("resize",n),n(),function(){document.removeEventListener("scroll",n),document.removeEventListener("resize",n)}}))},N="tableOfContents_35-E",L="table-of-contents__link";function U(e){var t=e.toc,a=e.isChild;return t.length?n.createElement("ul",{className:a?"":"table-of-contents table-of-contents__left-border"},t.map((function(e){return n.createElement("li",{key:e.id},n.createElement("a",{href:"#"+e.id,className:L,dangerouslySetInnerHTML:{__html:e.value}}),n.createElement(U,{isChild:!0,toc:e.children}))}))):null}var T=function(e){var t=e.toc;return _(L,"table-of-contents__link--active",100),n.createElement("div",{className:(0,b.Z)(N,"thin-scrollbar")},n.createElement(U,{toc:t}))},k=a(2122),y=a(9756),w="iconEdit_2_ui",A=function(e){var t=e.className,a=(0,y.Z)(e,["className"]);return n.createElement("svg",(0,k.Z)({fill:"currentColor",height:"1.2em",width:"1.2em",preserveAspectRatio:"xMidYMid meet",role:"img",viewBox:"0 0 40 40",className:(0,b.Z)(w,t),"aria-label":"Edit page"},a),n.createElement("g",null,n.createElement("path",{d:"m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"})))};function Z(e){var t=e.editUrl;return n.createElement("a",{href:t,target:"_blank",rel:"noreferrer noopener"},n.createElement(A,null),n.createElement(r.Z,{id:"theme.common.editThisPage",description:"The link label to edit the current page"},"Edit this page"))}var C="docTitle_3a4h",x="docItemContainer_33ec",V="docItemCol_3FnS";var B=function(e){var t,a=e.content,l=a.metadata,r=a.frontMatter,s=r.image,c=r.keywords,d=r.hide_title,m=r.hide_table_of_contents,u=l.description,h=l.title,E=l.editUrl,g=l.lastUpdatedAt,_=l.formattedLastUpdatedAt,N=l.lastUpdatedBy,L=(0,o.useActivePlugin)({failfast:!0}).pluginId,U=(0,o.useVersions)(L),k=(0,o.useActiveVersion)(L),y=U.length>1,w=r.title||h;return n.createElement(n.Fragment,null,n.createElement(p.Z,{title:w,description:u,keywords:c,image:s}),n.createElement("div",{className:"row"},n.createElement("div",{className:(0,b.Z)("col",(t={},t[V]=!m,t))},n.createElement(v,null),n.createElement("div",{className:x},n.createElement("article",null,y&&n.createElement("div",null,n.createElement("span",{className:"badge badge--secondary"},"Version: ",k.label)),!d&&n.createElement("header",null,n.createElement("h1",{className:C},h)),n.createElement("div",{className:"markdown"},n.createElement(a,null))),(E||g||N)&&n.createElement("div",{className:"margin-vert--xl"},n.createElement("div",{className:"row"},n.createElement("div",{className:"col"},E&&n.createElement(Z,{editUrl:E})),(g||N)&&n.createElement(f,{lastUpdatedAt:g,formattedLastUpdatedAt:_,lastUpdatedBy:N}))),n.createElement("div",{className:"margin-vert--lg"},n.createElement(i,{metadata:l})))),!m&&a.toc&&n.createElement("div",{className:"col col--3"},n.createElement(T,{toc:a.toc}))))}}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[918],{4673:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return D}});var n=a(7294),l=a(6742),r=a(4973);var i=function(e){var t=e.metadata;return n.createElement("nav",{className:"pagination-nav docusaurus-mt-lg","aria-label":(0,r.I)({id:"theme.docs.paginator.navAriaLabel",message:"Docs pages navigation",description:"The ARIA label for the docs pagination"})},n.createElement("div",{className:"pagination-nav__item"},t.previous&&n.createElement(l.Z,{className:"pagination-nav__link",to:t.previous.permalink},n.createElement("div",{className:"pagination-nav__sublabel"},n.createElement(r.Z,{id:"theme.docs.paginator.previous",description:"The label used to navigate to the previous doc"},"Previous")),n.createElement("div",{className:"pagination-nav__label"},"\xab ",t.previous.title))),n.createElement("div",{className:"pagination-nav__item pagination-nav__item--next"},t.next&&n.createElement(l.Z,{className:"pagination-nav__link",to:t.next.permalink},n.createElement("div",{className:"pagination-nav__sublabel"},n.createElement(r.Z,{id:"theme.docs.paginator.next",description:"The label used to navigate to the next doc"},"Next")),n.createElement("div",{className:"pagination-nav__label"},t.next.title," \xbb"))))},s=a(2263),o=a(907),c=a(9732);function d(e){var t=e.siteTitle,a=e.versionLabel;return n.createElement(r.Z,{id:"theme.docs.versions.unreleasedVersionLabel",description:"The label used to tell the user that he's browsing an unreleased doc version",values:{siteTitle:t,versionLabel:n.createElement("b",null,a)}},"This is unreleased documentation for {siteTitle} {versionLabel} version.")}function m(e){var t=e.siteTitle,a=e.versionLabel;return n.createElement(r.Z,{id:"theme.docs.versions.unmaintainedVersionLabel",description:"The label used to tell the user that he's browsing an unmaintained doc version",values:{siteTitle:t,versionLabel:n.createElement("b",null,a)}},"This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.")}function u(e){var t=e.versionLabel,a=e.to,i=e.onClick;return n.createElement(r.Z,{id:"theme.docs.versions.latestVersionSuggestionLabel",description:"The label userd to tell the user that he's browsing an unmaintained doc version",values:{versionLabel:t,latestVersionLink:n.createElement("b",null,n.createElement(l.Z,{to:a,onClick:i},n.createElement(r.Z,{id:"theme.docs.versions.latestVersionLinkLabel",description:"The label used for the latest version suggestion link label"},"latest version")))}},"For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).")}var v=function(){var e=(0,s.Z)().siteConfig.title,t=(0,o.gA)({failfast:!0}).pluginId,a=(0,c.J)(t).savePreferredVersionName,l=(0,o.zu)(t),r=(0,o.Jo)(t),i=r.latestDocSuggestion,v=r.latestVersionSuggestion;if(!v)return n.createElement(n.Fragment,null);var h,p=null!=i?i:(h=v).docs.find((function(e){return e.id===h.mainDocId}));return n.createElement("div",{className:"alert alert--warning margin-bottom--md",role:"alert"},n.createElement("div",null,"current"===l.name?n.createElement(d,{siteTitle:e,versionLabel:l.label}):n.createElement(m,{siteTitle:e,versionLabel:l.label})),n.createElement("div",{className:"margin-top--md"},n.createElement(u,{versionLabel:v.label,to:p.path,onClick:function(){return a(v.name)}})))},h=a(1217);function p(e){var t=e.lastUpdatedAt,a=e.formattedLastUpdatedAt;return n.createElement(r.Z,{id:"theme.lastUpdated.atDate",description:"The words used to describe on which date a page has been last updated",values:{date:n.createElement("b",null,n.createElement("time",{dateTime:new Date(1e3*t).toISOString()},a))}}," on {date}")}function E(e){var t=e.lastUpdatedBy;return n.createElement(r.Z,{id:"theme.lastUpdated.byUser",description:"The words used to describe by who the page has been last updated",values:{user:n.createElement("b",null,t)}}," by {user}")}function g(e){var t=e.lastUpdatedAt,a=e.formattedLastUpdatedAt,l=e.lastUpdatedBy;return n.createElement(n.Fragment,null,n.createElement(r.Z,{id:"theme.lastUpdated.lastUpdatedAtBy",description:"The sentence used to display when a page has been last updated, and by who",values:{atDate:t&&a?n.createElement(p,{lastUpdatedAt:t,formattedLastUpdatedAt:a}):"",byUser:l?n.createElement(E,{lastUpdatedBy:l}):""}},"Last updated{atDate}{byUser}"),!1)}var f=a(6010);var b=function(e,t,a){var l=(0,n.useState)(void 0),r=l[0],i=l[1];(0,n.useEffect)((function(){function n(){var n=function(){var e=Array.from(document.getElementsByClassName("anchor")),t=e.find((function(e){return e.getBoundingClientRect().top>=a}));if(t){if(t.getBoundingClientRect().top>=a){var n=e[e.indexOf(t)-1];return null!=n?n:t}return t}return e[e.length-1]}();if(n)for(var l=0,s=!1,o=document.getElementsByClassName(e);l<o.length&&!s;){var c=o[l],d=c.href,m=decodeURIComponent(d.substring(d.indexOf("#")+1));n.id===m&&(r&&r.classList.remove(t),c.classList.add(t),i(c),s=!0),l+=1}}return document.addEventListener("scroll",n),document.addEventListener("resize",n),n(),function(){document.removeEventListener("scroll",n),document.removeEventListener("resize",n)}}))},_="tableOfContents_35-E",L="table-of-contents__link";function N(e){var t=e.toc,a=e.isChild;return t.length?n.createElement("ul",{className:a?"":"table-of-contents table-of-contents__left-border"},t.map((function(e){return n.createElement("li",{key:e.id},n.createElement("a",{href:"#"+e.id,className:L,dangerouslySetInnerHTML:{__html:e.value}}),n.createElement(N,{isChild:!0,toc:e.children}))}))):null}var U=function(e){var t=e.toc;return b(L,"table-of-contents__link--active",100),n.createElement("div",{className:(0,f.Z)(_,"thin-scrollbar")},n.createElement(N,{toc:t}))},k=a(2122),T=a(9756),Z="iconEdit_2_ui",y=["className"],w=function(e){var t=e.className,a=(0,T.Z)(e,y);return n.createElement("svg",(0,k.Z)({fill:"currentColor",height:"20",width:"20",viewBox:"0 0 40 40",className:(0,f.Z)(Z,t),"aria-hidden":"true"},a),n.createElement("g",null,n.createElement("path",{d:"m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"})))};function A(e){var t=e.editUrl;return n.createElement("a",{href:t,target:"_blank",rel:"noreferrer noopener"},n.createElement(w,null),n.createElement(r.Z,{id:"theme.common.editThisPage",description:"The link label to edit the current page"},"Edit this page"))}var C=a(6159),B="docItemContainer_33ec",I="lastUpdated_3DPF",x="docItemCol_3FnS";var D=function(e){var t,a=e.content,l=a.metadata,r=a.frontMatter,s=r.image,c=r.keywords,d=r.hide_title,m=r.hide_table_of_contents,u=l.description,p=l.title,E=l.editUrl,b=l.lastUpdatedAt,_=l.formattedLastUpdatedAt,L=l.lastUpdatedBy,N=(0,o.gA)({failfast:!0}).pluginId,k=(0,o.gB)(N),T=(0,o.zu)(N),Z=k.length>1,y=!d&&void 0===a.contentTitle;return n.createElement(n.Fragment,null,n.createElement(h.Z,{title:p,description:u,keywords:c,image:s}),n.createElement("div",{className:"row"},n.createElement("div",{className:(0,f.Z)("col",(t={},t[x]=!m,t))},n.createElement(v,null),n.createElement("div",{className:B},n.createElement("article",null,Z&&n.createElement("span",{className:"badge badge--secondary"},"Version: ",T.label),n.createElement("div",{className:"markdown"},y&&n.createElement(C.N,null,p),n.createElement(a,null)),(E||b||L)&&n.createElement("footer",{className:"row docusaurus-mt-lg"},n.createElement("div",{className:"col"},E&&n.createElement(A,{editUrl:E})),n.createElement("div",{className:(0,f.Z)("col",I)},(b||L)&&n.createElement(g,{lastUpdatedAt:b,formattedLastUpdatedAt:_,lastUpdatedBy:L})))),n.createElement(i,{metadata:l}))),!m&&a.toc&&n.createElement("div",{className:"col col--3"},n.createElement(U,{toc:a.toc}))))}},6159:function(e,t,a){"use strict";a.d(t,{N:function(){return u},Z:function(){return v}});var n=a(9756),l=a(2122),r=a(7294),i=a(6010),s=a(4973),o=a(9732),c="enhancedAnchor_2LWZ",d="h1Heading_27L5",m=["id"],u=function(e){var t=Object.assign({},e);return r.createElement("header",null,r.createElement("h1",(0,l.Z)({},t,{id:void 0,className:d}),t.children))},v=function(e){return"h1"===e?u:(t=e,function(e){var a,l=e.id,d=(0,n.Z)(e,m),u=(0,o.LU)().navbar.hideOnScroll;return l?r.createElement(t,d,r.createElement("a",{"aria-hidden":"true",tabIndex:-1,className:(0,i.Z)("anchor",(a={},a[c]=!u,a)),id:l}),d.children,r.createElement("a",{className:"hash-link",href:"#"+l,title:(0,s.I)({id:"theme.common.headingLinkTitle",message:"Direct link to heading",description:"Title for link to heading"})},"#")):r.createElement(t,d)});var t}}}]);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[608],{4608:function(e,t,a){"use strict";a.r(t);var n=a(7294),o=a(2611),l=a(4973);t.default=function(){return n.createElement(o.Z,{title:"Page Not Found"},n.createElement("main",{className:"container margin-vert--xl"},n.createElement("div",{className:"row"},n.createElement("div",{className:"col col--6 col--offset-3"},n.createElement("h1",{className:"hero__title"},n.createElement(l.Z,{id:"theme.NotFound.title",description:"The title of the 404 page"},"Page Not Found")),n.createElement("p",null,n.createElement(l.Z,{id:"theme.NotFound.p1",description:"The first paragraph of the 404 page"},"We could not find what you were looking for.")),n.createElement("p",null,n.createElement(l.Z,{id:"theme.NotFound.p2",description:"The 2nd paragraph of the 404 page"},"Please contact the owner of the site that linked you to the original URL and let them know their link is broken."))))))}}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[608],{4608:function(e,t,a){"use strict";a.r(t);var n=a(7294),o=a(9349),i=a(4973);t.default=function(){return n.createElement(o.Z,{title:(0,i.I)({id:"theme.NotFound.title",message:"Page Not Found"})},n.createElement("main",{className:"container margin-vert--xl"},n.createElement("div",{className:"row"},n.createElement("div",{className:"col col--6 col--offset-3"},n.createElement("h1",{className:"hero__title"},n.createElement(i.Z,{id:"theme.NotFound.title",description:"The title of the 404 page"},"Page Not Found")),n.createElement("p",null,n.createElement(i.Z,{id:"theme.NotFound.p1",description:"The first paragraph of the 404 page"},"We could not find what you were looking for.")),n.createElement("p",null,n.createElement(i.Z,{id:"theme.NotFound.p2",description:"The 2nd paragraph of the 404 page"},"Please contact the owner of the site that linked you to the original URL and let them know their link is broken."))))))}}}]);
\ No newline at end of file
This diff is collapsed.
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[651],{7917:function(e,t,n){"use strict";n.r(t),n.d(t,{frontMatter:function(){return s},metadata:function(){return r},toc:function(){return o},default:function(){return c}});var a=n(2122),l=n(9756),i=(n(7294),n(3905)),s={title:"Getting started",slug:"/"},r={unversionedId:"quickstart",id:"quickstart",isDocsHomePage:!1,title:"Getting started",description:"Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API.",source:"@site/docs/quickstart.md",sourceDirName:".",slug:"/",permalink:"/docs/",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/quickstart.md",version:"current",frontMatter:{title:"Getting started",slug:"/"},sidebar:"leftSidebar",next:{title:"HTTP handler",permalink:"/docs/http-handler"}},o=[{value:"Installing Pistache",id:"installing-pistache",children:[]},{value:"Serving requests",id:"serving-requests",children:[{value:"Include",id:"include",children:[]},{value:"Hello world",id:"hello-world",children:[]},{value:"Final touch",id:"final-touch",children:[]}]}],p={toc:o};function c(e){var t=e.components,n=(0,l.Z)(e,["components"]);return(0,i.kt)("wrapper",(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/pistache.h>\n")),(0,i.kt)("h2",{id:"installing-pistache"},"Installing Pistache"),(0,i.kt)("p",null,(0,i.kt)("a",{parentName:"p",href:"https://git-scm.com"},"git")," is needed to retrieve the sources. Compiling the sources will require ",(0,i.kt)("a",{parentName:"p",href:"https://cmake.org"},"CMake")," to generate build files and a recent compiler that supports C++17."),(0,i.kt)("p",null,"If you're on Ubuntu and want to skip the compilation process you can add the official PPA providing nightly builds:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"sudo add-apt-repository ppa:pistache+team/unstable\nsudo apt update\nsudo apt install libpistache-dev\n")),(0,i.kt)("p",null,"Otherwise, here's how to build and install the latest release:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"git clone https://github.com/pistacheio/pistache.git\ncd pistache\nmeson setup build\nmeson install -C build\n")),(0,i.kt)("p",null,"Also, Pistache does not support Windows yet, but should work fine under ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/windows/wsl/about"},"WSL"),"."),(0,i.kt)("h2",{id:"serving-requests"},"Serving requests"),(0,i.kt)("h3",{id:"include"},"Include"),(0,i.kt)("p",null,"First, let\u2019s start by including the right header."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/endpoint.h>\n")),(0,i.kt)("h3",{id:"hello-world"},"Hello world"),(0,i.kt)("p",null,"Requests received by Pistache are handled with an ",(0,i.kt)("inlineCode",{parentName:"p"},"Http::Handler"),"."),(0,i.kt)("p",null,"Let\u2019s start by defining a simple ",(0,i.kt)("inlineCode",{parentName:"p"},"HelloHandler"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},'using namespace Pistache;\n\nclass HelloHandler : public Http::Handler {\npublic:\n\n HTTP_PROTOTYPE(HelloHandler)\n\n void onRequest(const Http::Request& request, Http::ResponseWriter response) {\n response.send(Http::Code::Ok, "Hello, World\\n");\n }\n};\n')),(0,i.kt)("p",null,"Handlers must inherit the ",(0,i.kt)("inlineCode",{parentName:"p"},"Http::Handler")," class and at least define the ",(0,i.kt)("inlineCode",{parentName:"p"},"onRequest")," member function. They must also define a ",(0,i.kt)("inlineCode",{parentName:"p"},"clone()")," member function. Simple handlers can use the special ",(0,i.kt)("inlineCode",{parentName:"p"},"HTTP_PROTOTYPE")," macro, passing in the name of the class. The macro will take care of defining the ",(0,i.kt)("inlineCode",{parentName:"p"},"clone()")," member function for you."),(0,i.kt)("h3",{id:"final-touch"},"Final touch"),(0,i.kt)("p",null,"After defining the handler, the server can now be started:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"int main() {\n Address addr(Ipv4::any(), Port(9080));\n\n auto opts = Http::Endpoint::options().threads(1);\n Http::Endpoint server(addr);\n server.init(opts);\n server.setHandler(Http::make_handler<HelloHandler>());\n server.serve();\n}\n")),(0,i.kt)("p",null,"For simplicity, you can also use the special ",(0,i.kt)("inlineCode",{parentName:"p"},"listenAndServe")," function that will automatically create an endpoint and instantiate your handler:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},'int main() {\n Http::listenAndServe<HelloHandler>("*:9080");\n}\n')),(0,i.kt)("p",null,"And that\u2019s it, now you can fire up your favorite curl request and observe the final result:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"curl http://localhost:9080/\nHello, World\n")),(0,i.kt)("p",null,"Complete code for this example can be found on GitHub: ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc"},"examples/hello_server.cc")))}c.isMDXComponent=!0}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[651],{7917:function(e,t,n){"use strict";n.r(t),n.d(t,{frontMatter:function(){return r},contentTitle:function(){return o},metadata:function(){return p},toc:function(){return c},default:function(){return u}});var a=n(2122),l=n(9756),i=(n(7294),n(3905)),s=["components"],r={title:"Getting started",slug:"/"},o=void 0,p={unversionedId:"quickstart",id:"quickstart",isDocsHomePage:!1,title:"Getting started",description:"Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API.",source:"@site/docs/quickstart.md",sourceDirName:".",slug:"/",permalink:"/docs/",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/quickstart.md",version:"current",frontMatter:{title:"Getting started",slug:"/"},sidebar:"leftSidebar",previous:{title:"HTTP handler",permalink:"/docs/http-handler"},next:{title:"REST description",permalink:"/docs/rest-description"}},c=[{value:"Installing Pistache",id:"installing-pistache",children:[]},{value:"Serving requests",id:"serving-requests",children:[{value:"Include",id:"include",children:[]},{value:"Hello world",id:"hello-world",children:[]},{value:"Final touch",id:"final-touch",children:[]}]}],d={toc:c};function u(e){var t=e.components,n=(0,l.Z)(e,s);return(0,i.kt)("wrapper",(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/pistache.h>\n")),(0,i.kt)("h2",{id:"installing-pistache"},"Installing Pistache"),(0,i.kt)("p",null,(0,i.kt)("a",{parentName:"p",href:"https://git-scm.com"},"git")," is needed to retrieve the sources. Compiling the sources will require ",(0,i.kt)("a",{parentName:"p",href:"https://cmake.org"},"CMake")," to generate build files and a recent compiler that supports C++17."),(0,i.kt)("p",null,"If you're on Ubuntu and want to skip the compilation process you can add the official PPA providing nightly builds:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"sudo add-apt-repository ppa:pistache+team/unstable\nsudo apt update\nsudo apt install libpistache-dev\n")),(0,i.kt)("p",null,"Otherwise, here's how to build and install the latest release:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"git clone https://github.com/pistacheio/pistache.git\ncd pistache\nmeson setup build\nmeson install -C build\n")),(0,i.kt)("p",null,"Also, Pistache does not support Windows yet, but should work fine under ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/windows/wsl/about"},"WSL"),"."),(0,i.kt)("h2",{id:"serving-requests"},"Serving requests"),(0,i.kt)("h3",{id:"include"},"Include"),(0,i.kt)("p",null,"First, let\u2019s start by including the right header."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/endpoint.h>\n")),(0,i.kt)("h3",{id:"hello-world"},"Hello world"),(0,i.kt)("p",null,"Requests received by Pistache are handled with an ",(0,i.kt)("inlineCode",{parentName:"p"},"Http::Handler"),"."),(0,i.kt)("p",null,"Let\u2019s start by defining a simple ",(0,i.kt)("inlineCode",{parentName:"p"},"HelloHandler"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},'using namespace Pistache;\n\nclass HelloHandler : public Http::Handler {\npublic:\n\n HTTP_PROTOTYPE(HelloHandler)\n\n void onRequest(const Http::Request& request, Http::ResponseWriter response) {\n response.send(Http::Code::Ok, "Hello, World\\n");\n }\n};\n')),(0,i.kt)("p",null,"Handlers must inherit the ",(0,i.kt)("inlineCode",{parentName:"p"},"Http::Handler")," class and at least define the ",(0,i.kt)("inlineCode",{parentName:"p"},"onRequest")," member function. They must also define a ",(0,i.kt)("inlineCode",{parentName:"p"},"clone()")," member function. Simple handlers can use the special ",(0,i.kt)("inlineCode",{parentName:"p"},"HTTP_PROTOTYPE")," macro, passing in the name of the class. The macro will take care of defining the ",(0,i.kt)("inlineCode",{parentName:"p"},"clone()")," member function for you."),(0,i.kt)("h3",{id:"final-touch"},"Final touch"),(0,i.kt)("p",null,"After defining the handler, the server can now be started:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"int main() {\n Address addr(Ipv4::any(), Port(9080));\n\n auto opts = Http::Endpoint::options().threads(1);\n Http::Endpoint server(addr);\n server.init(opts);\n server.setHandler(Http::make_handler<HelloHandler>());\n server.serve();\n}\n")),(0,i.kt)("p",null,"For simplicity, you can also use the special ",(0,i.kt)("inlineCode",{parentName:"p"},"listenAndServe")," function that will automatically create an endpoint and instantiate your handler:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},'int main() {\n Http::listenAndServe<HelloHandler>("*:9080");\n}\n')),(0,i.kt)("p",null,"And that\u2019s it, now you can fire up your favorite curl request and observe the final result:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-shell"},"curl http://localhost:9080/\nHello, World\n")),(0,i.kt)("p",null,"Complete code for this example can be found on GitHub: ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc"},"examples/hello_server.cc")))}u.isMDXComponent=!0}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[659],{4660:function(t,e,i){"use strict";i.r(e),i.d(e,{frontMatter:function(){return c},contentTitle:function(){return p},metadata:function(){return a},toc:function(){return d},default:function(){return l}});var r=i(2122),s=i(9756),n=(i(7294),i(3905)),o=["components"],c={title:"REST description"},p=void 0,a={unversionedId:"rest-description",id:"rest-description",isDocsHomePage:!1,title:"REST description",description:"Documentation writing for this part is still in progress, please refer to the restdescription example.",source:"@site/docs/rest-description.md",sourceDirName:".",slug:"/rest-description",permalink:"/docs/rest-description",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/rest-description.md",version:"current",frontMatter:{title:"REST description"},sidebar:"leftSidebar",previous:{title:"Getting started",permalink:"/docs/"},next:{title:"Routing",permalink:"/docs/routing"}},d=[],u={toc:d};function l(t){var e=t.components,i=(0,s.Z)(t,o);return(0,n.kt)("wrapper",(0,r.Z)({},u,i,{components:e,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Documentation writing for this part is still in progress, please refer to the ",(0,n.kt)("a",{parentName:"p",href:"https://github.com/pistacheio/pistache/blob/master/examples/rest_description.cc"},"rest_description")," example."))}l.isMDXComponent=!0}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[659],{4660:function(t,e,i){"use strict";i.r(e),i.d(e,{frontMatter:function(){return n},metadata:function(){return c},toc:function(){return p},default:function(){return d}});var r=i(2122),s=i(9756),o=(i(7294),i(3905)),n={title:"REST description"},c={unversionedId:"rest-description",id:"rest-description",isDocsHomePage:!1,title:"REST description",description:"Documentation writing for this part is still in progress, please refer to the restdescription example.",source:"@site/docs/rest-description.md",sourceDirName:".",slug:"/rest-description",permalink:"/docs/rest-description",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/rest-description.md",version:"current",frontMatter:{title:"REST description"}},p=[],a={toc:p};function d(t){var e=t.components,i=(0,s.Z)(t,["components"]);return(0,o.kt)("wrapper",(0,r.Z)({},a,i,{components:e,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Documentation writing for this part is still in progress, please refer to the ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/pistacheio/pistache/blob/master/examples/rest_description.cc"},"rest_description")," example."))}d.isMDXComponent=!0}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[53],{9054:function(e){"use strict";e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","isLast":true,"docsSidebars":{"leftSidebar":[{"collapsed":true,"type":"category","label":"Pistache","items":[{"type":"link","label":"Getting started","href":"/docs/"},{"type":"link","label":"HTTP handler","href":"/docs/http-handler"},{"type":"link","label":"Asynchronous HTTP programming","href":"/docs/asynchronous-http-programming"},{"type":"link","label":"Headers","href":"/docs/headers"},{"type":"link","label":"Routing","href":"/docs/routing"}]}]},"permalinkToSidebar":{"/docs/asynchronous-http-programming":"leftSidebar","/docs/headers":"leftSidebar","/docs/http-handler":"leftSidebar","/docs/":"leftSidebar","/docs/routing":"leftSidebar"}}')}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[53],{9054:function(e){"use strict";e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","isLast":true,"docsSidebars":{"leftSidebar":[{"type":"link","label":"Asynchronous HTTP programming","href":"/docs/asynchronous-http-programming"},{"type":"link","label":"Headers","href":"/docs/headers"},{"type":"link","label":"HTTP handler","href":"/docs/http-handler"},{"type":"link","label":"Getting started","href":"/docs/"},{"type":"link","label":"REST description","href":"/docs/rest-description"},{"type":"link","label":"Routing","href":"/docs/routing"}]},"permalinkToSidebar":{"/docs/asynchronous-http-programming":"leftSidebar","/docs/headers":"leftSidebar","/docs/http-handler":"leftSidebar","/docs/":"leftSidebar","/docs/rest-description":"leftSidebar","/docs/routing":"leftSidebar"}}')}}]);
\ No newline at end of file
This diff is collapsed.
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[195],{6252:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return d}});var n=a(2122),l=a(7294),r=a(6010),i=a(2611),s=a(6742),c=a(2263),u=a(4996),m={heroBanner:"heroBanner_3P7f",buttons:"buttons_1r9m",features:"features_3azU",featureImage:"featureImage_ZtzX"},o=[{title:"Modern API",imageUrl:"img/undraw_futuristic_interface.svg",description:l.createElement(l.Fragment,null,"Written in pure C++17 and providing a low-level HTTP abstraction, Pistache makes playing with its modern API fun and easy, just take a look at the quickstart")},{title:"What's in the box",imageUrl:"img/undraw_accept_request.svg",description:l.createElement(l.Fragment,null,l.createElement("ul",null,l.createElement("li",null,"A multi-threaded HTTP server to build your APIs"),l.createElement("li",null,"An asynchronous HTTP client to request APIs"),l.createElement("li",null,"An HTTP router to dispatch requests to C++ functions"),l.createElement("li",null,"A REST description DSL to easily define your APIs"),l.createElement("li",null,"Type-safe headers and MIME types implementation")))},{title:"Use it",imageUrl:"img/undraw_version_control.svg",description:l.createElement(l.Fragment,null,l.createElement("ul",null,l.createElement("li",null,"Clone it on ",l.createElement("a",{href:"https://github.com/pistacheio/pistache"},"GitHub")),l.createElement("li",null,"Start with the ",l.createElement("a",{href:"docs/"},"quickstart")),l.createElement("li",null,"Read the full user's ",l.createElement("a",{href:"docs/http-handler"},"guide")),l.createElement("li",null,"Have issues with it? Fill an ",l.createElement("a",{href:"https://github.com/pistacheio/pistache/issues"},"issue"))))}];function h(e){var t=e.imageUrl,a=e.title,n=e.description,i=(0,u.Z)(t);return l.createElement("div",{className:(0,r.Z)("col col--4",m.feature)},i&&l.createElement("div",{className:"text--center"},l.createElement("img",{className:m.featureImage,src:i,alt:a})),l.createElement("h3",null,a),l.createElement("p",null,n))}var d=function(){var e=(0,c.default)().siteConfig,t=void 0===e?{}:e;return l.createElement(i.Z,{description:"Description will go into a meta tag in <head />"},l.createElement("header",{className:(0,r.Z)("hero hero--primary",m.heroBanner)},l.createElement("div",{className:"container"},l.createElement("h1",{className:"hero__title"},t.title),l.createElement("p",{className:"hero__subtitle"},t.tagline),l.createElement("div",{className:m.buttons},l.createElement(s.Z,{className:(0,r.Z)("button button--outline button--secondary button--lg",m.getStarted),to:(0,u.Z)("docs/")},"Get Started")))),l.createElement("main",null,o&&o.length>0&&l.createElement("section",{className:m.features},l.createElement("div",{className:"container"},l.createElement("div",{className:"row"},o.map((function(e,t){return l.createElement(h,(0,n.Z)({key:t},e))})))))))}}}]);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[489],{2509:function(e,t,n){"use strict";n.r(t),n.d(t,{frontMatter:function(){return s},contentTitle:function(){return l},metadata:function(){return c},toc:function(){return p},default:function(){return m}});var a=n(2122),r=n(9756),o=(n(7294),n(3905)),i=["components"],s={title:"Asynchronous HTTP programming"},l=void 0,c={unversionedId:"asynchronous-http-programming",id:"asynchronous-http-programming",isDocsHomePage:!1,title:"Asynchronous HTTP programming",description:"Interfaces provided by Pistaches are asynchronous and non-blocking. Asynchronous programming allows for code to continue executing even if the result of a given call is not available yet. Calls that provide an asynchronous interface are referred to asynchronous calls.",source:"@site/docs/asynchronous-http-programming.md",sourceDirName:".",slug:"/asynchronous-http-programming",permalink:"/docs/asynchronous-http-programming",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/asynchronous-http-programming.md",version:"current",frontMatter:{title:"Asynchronous HTTP programming"},sidebar:"leftSidebar",next:{title:"Headers",permalink:"/docs/headers"}},p=[],h={toc:p};function m(e){var t=e.components,n=(0,r.Z)(e,i);return(0,o.kt)("wrapper",(0,a.Z)({},h,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Interfaces provided by Pistaches are ",(0,o.kt)("em",{parentName:"p"},"asynchronous")," and ",(0,o.kt)("em",{parentName:"p"},"non-blocking"),". Asynchronous programming allows for code to continue executing even if the result of a given call is not available yet. Calls that provide an asynchronous interface are referred to ",(0,o.kt)("em",{parentName:"p"},"asynchronous calls"),"."),(0,o.kt)("p",null,"An example of such a call is the ",(0,o.kt)("inlineCode",{parentName:"p"},"send()")," function provided by the ",(0,o.kt)("inlineCode",{parentName:"p"},"ResponseWriter")," interface. This function returns the number of bytes written to the socket file descriptor associated to the connection. However, instead of returning directly the value to the caller and thus blocking the caller, it wraps the value into a component called a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise"),"."),(0,o.kt)("p",null,"A ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," is the Pistache\u2019s implementation of the ",(0,o.kt)("a",{parentName:"p",href:"https://promisesaplus.com"},"Promises/A+")," standard available in many JavaScript implementations. Simply put, during an asynchronous call, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," separates the launch of an asynchronous operation from the retrieval of its result. While the asynchronous might still be running, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise<T>")," is directly returned to the caller to retrieve the final result when it becomes available. A so called continuation can be attach to a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," to execute a callback when the result becomes available (when the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," has been resolved or fulfilled)."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-cpp"},'auto res = response.send(Http::Code::Ok, "Hello World");\nres.then(\n [](ssize_t bytes) { std::cout << bytes << " bytes have been sent\\n" },\n Async::NoExcept\n);\n')),(0,o.kt)("p",null,"The ",(0,o.kt)("inlineCode",{parentName:"p"},"then()")," member is used to attach a callback to the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise"),". The first argument is a callable that will be called when the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," has been ",(0,o.kt)("strong",{parentName:"p"},"succesfully")," resolved. If, for some reason, an error occurs during the asynchronous operation, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," can be ",(0,o.kt)("strong",{parentName:"p"},"rejected")," and will then fail. In this case, the second callable will be called. ",(0,o.kt)("inlineCode",{parentName:"p"},"Async::NoExcept")," is a special callback that will call ",(0,o.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/error/terminate"},(0,o.kt)("inlineCode",{parentName:"a"},"std::terminate()"))," if the promise failed. This is the equivalent of the ",(0,o.kt)("inlineCode",{parentName:"p"},"noexcept")," keyword."),(0,o.kt)("p",null,"Other generic callbacks can also be used in this case:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"Async::IgnoreException")," will simply ignore the exception and let the program continue"),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"Async::Throw"),' will "rethrow" the exception up to an eventual promise call-chain. This has the same effect than the ',(0,o.kt)("inlineCode",{parentName:"li"},"throw")," keyword, except that it is suitable for promises")),(0,o.kt)("p",null,"Exceptions in promises callbacks are propagated through an ",(0,o.kt)("inlineCode",{parentName:"p"},"exception_ptr"),". Promises can also be chained together to create a whole asynchronous pipeline:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-cpp"},'auto fetchOp = fetchDatabase();\nfetchOp\n .then(\n [](const User& user) { return fetchUserInfo(user); },\n Async::Throw)\n .then(\n [](const UserInfo& info) { std::cout << "User name = " << info.name << \'\\n\'; },\n [](exception_ptr ptr) { std::cerr << "An exception occured during user retrieval\\n";}\n);\n')),(0,o.kt)("p",null,"Line 5 will propagate the exception if ",(0,o.kt)("inlineCode",{parentName:"p"},"fetchDatabase()")," failed and rejected the promise."))}m.isMDXComponent=!0}}]);
\ No newline at end of file
(self.webpackChunkpistache_io=self.webpackChunkpistache_io||[]).push([[489],{2509:function(e,t,n){"use strict";n.r(t),n.d(t,{frontMatter:function(){return i},metadata:function(){return s},toc:function(){return l},default:function(){return p}});var a=n(2122),r=n(9756),o=(n(7294),n(3905)),i={title:"Asynchronous HTTP programming"},s={unversionedId:"asynchronous-http-programming",id:"asynchronous-http-programming",isDocsHomePage:!1,title:"Asynchronous HTTP programming",description:"Interfaces provided by Pistaches are asynchronous and non-blocking. Asynchronous programming allows for code to continue executing even if the result of a given call is not available yet. Calls that provide an asynchronous interface are referred to asynchronous calls.",source:"@site/docs/asynchronous-http-programming.md",sourceDirName:".",slug:"/asynchronous-http-programming",permalink:"/docs/asynchronous-http-programming",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/asynchronous-http-programming.md",version:"current",frontMatter:{title:"Asynchronous HTTP programming"},sidebar:"leftSidebar",previous:{title:"HTTP handler",permalink:"/docs/http-handler"},next:{title:"Headers",permalink:"/docs/headers"}},l=[],c={toc:l};function p(e){var t=e.components,n=(0,r.Z)(e,["components"]);return(0,o.kt)("wrapper",(0,a.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"Interfaces provided by Pistaches are ",(0,o.kt)("em",{parentName:"p"},"asynchronous")," and ",(0,o.kt)("em",{parentName:"p"},"non-blocking"),". Asynchronous programming allows for code to continue executing even if the result of a given call is not available yet. Calls that provide an asynchronous interface are referred to ",(0,o.kt)("em",{parentName:"p"},"asynchronous calls"),"."),(0,o.kt)("p",null,"An example of such a call is the ",(0,o.kt)("inlineCode",{parentName:"p"},"send()")," function provided by the ",(0,o.kt)("inlineCode",{parentName:"p"},"ResponseWriter")," interface. This function returns the number of bytes written to the socket file descriptor associated to the connection. However, instead of returning directly the value to the caller and thus blocking the caller, it wraps the value into a component called a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise"),"."),(0,o.kt)("p",null,"A ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," is the Pistache\u2019s implementation of the ",(0,o.kt)("a",{parentName:"p",href:"https://promisesaplus.com"},"Promises/A+")," standard available in many JavaScript implementations. Simply put, during an asynchronous call, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," separates the launch of an asynchronous operation from the retrieval of its result. While the asynchronous might still be running, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise<T>")," is directly returned to the caller to retrieve the final result when it becomes available. A so called continuation can be attach to a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," to execute a callback when the result becomes available (when the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," has been resolved or fulfilled)."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-cpp"},'auto res = response.send(Http::Code::Ok, "Hello World");\nres.then(\n [](ssize_t bytes) { std::cout << bytes << " bytes have been sent\\n" },\n Async::NoExcept\n);\n')),(0,o.kt)("p",null,"The ",(0,o.kt)("inlineCode",{parentName:"p"},"then()")," member is used to attach a callback to the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise"),". The first argument is a callable that will be called when the ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," has been ",(0,o.kt)("strong",{parentName:"p"},"succesfully")," resolved. If, for some reason, an error occurs during the asynchronous operation, a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," can be ",(0,o.kt)("strong",{parentName:"p"},"rejected")," and will then fail. In this case, the second callable will be called. ",(0,o.kt)("inlineCode",{parentName:"p"},"Async::NoExcept")," is a special callback that will call ",(0,o.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/error/terminate"},(0,o.kt)("inlineCode",{parentName:"a"},"std::terminate()"))," if the promise failed. This is the equivalent of the ",(0,o.kt)("inlineCode",{parentName:"p"},"noexcept")," keyword."),(0,o.kt)("p",null,"Other generic callbacks can also be used in this case:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"Async::IgnoreException")," will simply ignore the exception and let the program continue"),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"Async::Throw"),' will "rethrow" the exception up to an eventual promise call-chain. This has the same effect than the ',(0,o.kt)("inlineCode",{parentName:"li"},"throw")," keyword, except that it is suitable for promises")),(0,o.kt)("p",null,"Exceptions in promises callbacks are propagated through an ",(0,o.kt)("inlineCode",{parentName:"p"},"exception_ptr"),". Promises can also be chained together to create a whole asynchronous pipeline:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-cpp"},'auto fetchOp = fetchDatabase();\nfetchOp\n .then(\n [](const User& user) { return fetchUserInfo(user); },\n Async::Throw)\n .then(\n [](const UserInfo& info) { std::cout << "User name = " << info.name << \'\\n\'; },\n [](exception_ptr ptr) { std::cerr << "An exception occured during user retrieval\\n";}\n);\n')),(0,o.kt)("p",null,"Line 5 will propagate the exception if ",(0,o.kt)("inlineCode",{parentName:"p"},"fetchDatabase()")," failed and rejected the promise."))}p.isMDXComponent=!0}}]);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -7,7 +7,7 @@ object-assign ...@@ -7,7 +7,7 @@ object-assign
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress /* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
* @license MIT */ * @license MIT */
/** @license React v0.19.1 /** @license React v0.20.2
* scheduler.production.min.js * scheduler.production.min.js
* *
* Copyright (c) Facebook, Inc. and its affiliates. * Copyright (c) Facebook, Inc. and its affiliates.
...@@ -25,7 +25,7 @@ object-assign ...@@ -25,7 +25,7 @@ object-assign
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
/** @license React v16.14.0 /** @license React v17.0.2
* react-dom.production.min.js * react-dom.production.min.js
* *
* Copyright (c) Facebook, Inc. and its affiliates. * Copyright (c) Facebook, Inc. and its affiliates.
...@@ -34,7 +34,7 @@ object-assign ...@@ -34,7 +34,7 @@ object-assign
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
/** @license React v16.14.0 /** @license React v17.0.2
* react.production.min.js * react.production.min.js
* *
* Copyright (c) Facebook, Inc. and its affiliates. * Copyright (c) Facebook, Inc. and its affiliates.
......
This diff is collapsed.
!function(){"use strict";var e,t,n,r,o,u={},i={};function f(e){var t=i[e];if(void 0!==t)return t.exports;var n=i[e]={id:e,loaded:!1,exports:{}};return u[e].call(n.exports,n,n.exports,f),n.loaded=!0,n.exports}f.m=u,f.c=i,e=[],f.O=function(t,n,r,o){if(!n){var u=1/0;for(a=0;a<e.length;a++){n=e[a][0],r=e[a][1],o=e[a][2];for(var i=!0,c=0;c<n.length;c++)(!1&o||u>=o)&&Object.keys(f.O).every((function(e){return f.O[e](n[c])}))?n.splice(c--,1):(i=!1,o<u&&(u=o));i&&(e.splice(a--,1),t=r())}return t}o=o||0;for(var a=e.length;a>0&&e[a-1][2]>o;a--)e[a]=e[a-1];e[a]=[n,r,o]},f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},f.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var o=Object.create(null);f.r(o);var u={};t=t||[null,n({}),n([]),n(n)];for(var i=2&r&&e;"object"==typeof i&&!~t.indexOf(i);i=n(i))Object.getOwnPropertyNames(i).forEach((function(t){u[t]=function(){return e[t]}}));return u.default=function(){return e},f.d(o,u),o},f.d=function(e,t){for(var n in t)f.o(t,n)&&!f.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},f.f={},f.e=function(e){return Promise.all(Object.keys(f.f).reduce((function(t,n){return f.f[n](e,t),t}),[]))},f.u=function(e){return"assets/js/"+({1:"f811e444",53:"935f2afb",195:"c4f5d8e4",427:"e7b197f4",489:"e7cdbb73",514:"1be78505",536:"e9d16704",592:"common",651:"8070e160",659:"88aa539f",918:"17896441"}[e]||e)+"."+{1:"2fd6d52d",53:"c6562d59",195:"e6c429b5",427:"3e7e0b5e",489:"ef50895a",514:"4c946095",536:"fee70ea2",592:"72b13248",608:"91815917",611:"b403c0ec",651:"9a7ae982",659:"e5ba6bb1",918:"68e6b261"}[e]+".js"},f.miniCssF=function(e){return"assets/css/styles.0030965e.css"},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="pistache-io:",f.l=function(e,t,n,u){if(r[e])r[e].push(t);else{var i,c;if(void 0!==n)for(var a=document.getElementsByTagName("script"),s=0;s<a.length;s++){var l=a[s];if(l.getAttribute("src")==e||l.getAttribute("data-webpack")==o+n){i=l;break}}i||(c=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,f.nc&&i.setAttribute("nonce",f.nc),i.setAttribute("data-webpack",o+n),i.src=e),r[e]=[t];var d=function(t,n){i.onerror=i.onload=null,clearTimeout(b);var o=r[e];if(delete r[e],i.parentNode&&i.parentNode.removeChild(i),o&&o.forEach((function(e){return e(n)})),t)return t(n)},b=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),c&&document.head.appendChild(i)}},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/",f.gca=function(e){return e={17896441:"918",f811e444:"1","935f2afb":"53",c4f5d8e4:"195",e7b197f4:"427",e7cdbb73:"489","1be78505":"514",e9d16704:"536",common:"592","8070e160":"651","88aa539f":"659"}[e]||e,f.p+f.u(e)},function(){var e={303:0,532:0};f.f.j=function(t,n){var r=f.o(e,t)?e[t]:void 0;if(0!==r)if(r)n.push(r[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var o=new Promise((function(n,o){r=e[t]=[n,o]}));n.push(r[2]=o);var u=f.p+f.u(t),i=new Error;f.l(u,(function(n){if(f.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var o=n&&("load"===n.type?"missing":n.type),u=n&&n.target&&n.target.src;i.message="Loading chunk "+t+" failed.\n("+o+": "+u+")",i.name="ChunkLoadError",i.type=o,i.request=u,r[1](i)}}),"chunk-"+t,t)}},f.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,o,u=n[0],i=n[1],c=n[2],a=0;for(r in i)f.o(i,r)&&(f.m[r]=i[r]);if(c)var s=c(f);for(t&&t(n);a<u.length;a++)o=u[a],f.o(e,o)&&e[o]&&e[o][0](),e[u[a]]=0;return f.O(s)},n=self.webpackChunkpistache_io=self.webpackChunkpistache_io||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}()}(); !function(){"use strict";var e,t,n,r,o,u={},i={};function f(e){var t=i[e];if(void 0!==t)return t.exports;var n=i[e]={id:e,loaded:!1,exports:{}};return u[e].call(n.exports,n,n.exports,f),n.loaded=!0,n.exports}f.m=u,f.c=i,e=[],f.O=function(t,n,r,o){if(!n){var u=1/0;for(a=0;a<e.length;a++){n=e[a][0],r=e[a][1],o=e[a][2];for(var i=!0,c=0;c<n.length;c++)(!1&o||u>=o)&&Object.keys(f.O).every((function(e){return f.O[e](n[c])}))?n.splice(c--,1):(i=!1,o<u&&(u=o));i&&(e.splice(a--,1),t=r())}return t}o=o||0;for(var a=e.length;a>0&&e[a-1][2]>o;a--)e[a]=e[a-1];e[a]=[n,r,o]},f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},f.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var o=Object.create(null);f.r(o);var u={};t=t||[null,n({}),n([]),n(n)];for(var i=2&r&&e;"object"==typeof i&&!~t.indexOf(i);i=n(i))Object.getOwnPropertyNames(i).forEach((function(t){u[t]=function(){return e[t]}}));return u.default=function(){return e},f.d(o,u),o},f.d=function(e,t){for(var n in t)f.o(t,n)&&!f.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},f.f={},f.e=function(e){return Promise.all(Object.keys(f.f).reduce((function(t,n){return f.f[n](e,t),t}),[]))},f.u=function(e){return"assets/js/"+({1:"f811e444",53:"935f2afb",195:"c4f5d8e4",427:"e7b197f4",489:"e7cdbb73",514:"1be78505",536:"e9d16704",592:"common",651:"8070e160",659:"88aa539f",918:"17896441"}[e]||e)+"."+{1:"4fd5c778",53:"e3ad223e",195:"25413e05",349:"4c4b6438",427:"18b1c9fa",489:"1b1aa4a3",514:"cfa83cbf",536:"d59286b0",592:"aaba9bd1",608:"e7ce046d",651:"a38ccea7",659:"ddd812ae",918:"7543c8e6"}[e]+".js"},f.miniCssF=function(e){return"assets/css/styles.35f9fda9.css"},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="pistache-io:",f.l=function(e,t,n,u){if(r[e])r[e].push(t);else{var i,c;if(void 0!==n)for(var a=document.getElementsByTagName("script"),s=0;s<a.length;s++){var d=a[s];if(d.getAttribute("src")==e||d.getAttribute("data-webpack")==o+n){i=d;break}}i||(c=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,f.nc&&i.setAttribute("nonce",f.nc),i.setAttribute("data-webpack",o+n),i.src=e),r[e]=[t];var l=function(t,n){i.onerror=i.onload=null,clearTimeout(b);var o=r[e];if(delete r[e],i.parentNode&&i.parentNode.removeChild(i),o&&o.forEach((function(e){return e(n)})),t)return t(n)},b=setTimeout(l.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=l.bind(null,i.onerror),i.onload=l.bind(null,i.onload),c&&document.head.appendChild(i)}},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/",f.gca=function(e){return e={17896441:"918",f811e444:"1","935f2afb":"53",c4f5d8e4:"195",e7b197f4:"427",e7cdbb73:"489","1be78505":"514",e9d16704:"536",common:"592","8070e160":"651","88aa539f":"659"}[e]||e,f.p+f.u(e)},function(){var e={303:0,532:0};f.f.j=function(t,n){var r=f.o(e,t)?e[t]:void 0;if(0!==r)if(r)n.push(r[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var o=new Promise((function(n,o){r=e[t]=[n,o]}));n.push(r[2]=o);var u=f.p+f.u(t),i=new Error;f.l(u,(function(n){if(f.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var o=n&&("load"===n.type?"missing":n.type),u=n&&n.target&&n.target.src;i.message="Loading chunk "+t+" failed.\n("+o+": "+u+")",i.name="ChunkLoadError",i.type=o,i.request=u,r[1](i)}}),"chunk-"+t,t)}},f.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,o,u=n[0],i=n[1],c=n[2],a=0;for(r in i)f.o(i,r)&&(f.m[r]=i[r]);if(c)var s=c(f);for(t&&t(n);a<u.length;a++)o=u[a],f.o(e,o)&&e[o]&&e[o][0](),e[u[a]]=0;return f.O(s)},n=self.webpackChunkpistache_io=self.webpackChunkpistache_io||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}()}();
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://pistache.io/blog</id>
<title>Pistache Blog</title>
<updated>2015-10-25T23:29:00.000Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://pistache.io/blog"/>
<subtitle>Pistache Blog</subtitle>
<icon>https://pistache.io/img/logo.png</icon>
</feed>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Pistache Blog</title>
<link>https://pistache.io/blog</link>
<description>Pistache Blog</description>
<lastBuildDate>Sun, 25 Oct 2015 23:29:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
</channel>
</rss>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://pistache.io/</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/asynchronous-http-programming</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/headers</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/http-handler</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/rest-description</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/routing</loc><changefreq>weekly</changefreq><priority>0.5</priority></url></urlset> <?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://pistache.io/</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/asynchronous-http-programming</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/headers</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/http-handler</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/rest-description</loc><changefreq>weekly</changefreq><priority>0.5</priority></url><url><loc>https://pistache.io/docs/routing</loc><changefreq>weekly</changefreq><priority>0.5</priority></url></urlset>
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment