Commit 20474c40 authored by kiplingw's avatar kiplingw

deploy: 6a073bd5

parent 9b70b4ff
This diff is collapsed.
(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{94:function(e,t,a){"use strict";a.r(t);var n=a(0),o=a.n(n),l=a(92);t.default=function(){return o.a.createElement(l.a,{title:"Page Not Found"},o.a.createElement("main",{className:"container margin-vert--xl"},o.a.createElement("div",{className:"row"},o.a.createElement("div",{className:"col col--6 col--offset-3"},o.a.createElement("h1",{className:"hero__title"},"Page Not Found"),o.a.createElement("p",null,"We could not find what you were looking for."),o.a.createElement("p",null,"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
(window.webpackJsonp=window.webpackJsonp||[]).push([[3],{82:function(e,t,a){"use strict";a.r(t);var n=a(0),l=a.n(n),r=a(24),c=a(83),i=a(22),o=a(87),m=a(86);var s=function(e){var t=e.metadata;return l.a.createElement("nav",{className:"pagination-nav","aria-label":"Blog list page navigation"},l.a.createElement("div",{className:"pagination-nav__item"},t.previous&&l.a.createElement(m.a,{className:"pagination-nav__link",to:t.previous.permalink},l.a.createElement("div",{className:"pagination-nav__sublabel"},"Previous"),l.a.createElement("div",{className:"pagination-nav__label"},"\xab ",t.previous.title))),l.a.createElement("div",{className:"pagination-nav__item pagination-nav__item--next"},t.next&&l.a.createElement(m.a,{className:"pagination-nav__link",to:t.next.permalink},l.a.createElement("div",{className:"pagination-nav__sublabel"},"Next"),l.a.createElement("div",{className:"pagination-nav__label"},t.next.title," \xbb"))))},d=a(85);var u=function(){var e=Object(i.default)().siteConfig.title,t=Object(d.useActivePlugin)({failfast:!0}).pluginId,a=Object(c.useDocsPreferredVersion)(t).savePreferredVersionName,n=Object(d.useActiveVersion)(t),r=Object(d.useDocVersionSuggestions)(t),o=r.latestDocSuggestion,s=r.latestVersionSuggestion;if(!s)return l.a.createElement(l.a.Fragment,null);var u,v=null!=o?o:(u=s).docs.find((function(e){return e.id===u.mainDocId}));return l.a.createElement("div",{className:"alert alert--warning margin-bottom--md",role:"alert"},"current"===n.name?l.a.createElement("div",null,"This is unreleased documentation for ",e," ",l.a.createElement("strong",null,n.label)," version."):l.a.createElement("div",null,"This is documentation for ",e," ",l.a.createElement("strong",null,n.label),", which is no longer actively maintained."),l.a.createElement("div",{className:"margin-top--md"},"For up-to-date documentation, see the"," ",l.a.createElement("strong",null,l.a.createElement(m.a,{to:v.path,onClick:function(){return a(s.name)}},"latest version"))," ","(",s.label,")."))},v=a(84);var E=function(e,t,a){var l=Object(n.useState)(void 0),r=l[0],c=l[1];Object(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,i=!1,o=document.getElementsByClassName(e);l<o.length&&!i;){var m=o[l],s=m.href,d=decodeURIComponent(s.substring(s.indexOf("#")+1));n.id===d&&(r&&r.classList.remove(t),m.classList.add(t),c(m),i=!0),l+=1}}return document.addEventListener("scroll",n),document.addEventListener("resize",n),n(),function(){document.removeEventListener("scroll",n),document.removeEventListener("resize",n)}}))},g=a(63),f=a.n(g),p="table-of-contents__link";function b(e){var t=e.toc,a=e.isChild;return t.length?l.a.createElement("ul",{className:a?"":"table-of-contents table-of-contents__left-border"},t.map((function(e){return l.a.createElement("li",{key:e.id},l.a.createElement("a",{href:"#"+e.id,className:p,dangerouslySetInnerHTML:{__html:e.value}}),l.a.createElement(b,{isChild:!0,toc:e.children}))}))):null}var N=function(e){var t=e.toc;return E(p,"table-of-contents__link--active",100),l.a.createElement("div",{className:Object(v.a)(f.a.tableOfContents,"thin-scrollbar")},l.a.createElement(b,{toc:t}))},h=a(3),_=a(7),O=a(64),j=a.n(O),w=function(e){var t=e.className,a=Object(_.a)(e,["className"]);return l.a.createElement("svg",Object(h.a)({fill:"currentColor",height:"1.2em",width:"1.2em",preserveAspectRatio:"xMidYMid meet",role:"img",viewBox:"0 0 40 40",className:Object(v.a)(j.a.iconEdit,t)},a),l.a.createElement("g",null,l.a.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"})))},k=a(65),y=a.n(k);t.default=function(e){var t,a=Object(i.default)().siteConfig.url,n=e.content,m=n.metadata,E=n.frontMatter,g=E.image,f=E.keywords,p=E.hide_title,b=E.hide_table_of_contents,h=m.description,_=m.title,O=m.permalink,j=m.editUrl,k=m.lastUpdatedAt,C=m.lastUpdatedBy,x=Object(d.useActivePlugin)({failfast:!0}).pluginId,L=Object(d.useVersions)(x),I=Object(d.useActiveVersion)(x),A=L.length>1,S=Object(c.useTitleFormatter)(_),V=Object(o.a)(g,{absolute:!0});return l.a.createElement(l.a.Fragment,null,l.a.createElement(r.a,null,l.a.createElement("title",null,S),l.a.createElement("meta",{property:"og:title",content:S}),h&&l.a.createElement("meta",{name:"description",content:h}),h&&l.a.createElement("meta",{property:"og:description",content:h}),f&&f.length&&l.a.createElement("meta",{name:"keywords",content:f.join(",")}),g&&l.a.createElement("meta",{property:"og:image",content:V}),g&&l.a.createElement("meta",{name:"twitter:image",content:V}),g&&l.a.createElement("meta",{name:"twitter:image:alt",content:"Image for "+_}),O&&l.a.createElement("meta",{property:"og:url",content:a+O}),O&&l.a.createElement("link",{rel:"canonical",href:a+O})),l.a.createElement("div",{className:"row"},l.a.createElement("div",{className:Object(v.a)("col",(t={},t[y.a.docItemCol]=!b,t))},l.a.createElement(u,null),l.a.createElement("div",{className:y.a.docItemContainer},l.a.createElement("article",null,A&&l.a.createElement("div",null,l.a.createElement("span",{className:"badge badge--secondary"},"Version: ",I.label)),!p&&l.a.createElement("header",null,l.a.createElement("h1",{className:y.a.docTitle},_)),l.a.createElement("div",{className:"markdown"},l.a.createElement(n,null))),(j||k||C)&&l.a.createElement("div",{className:"margin-vert--xl"},l.a.createElement("div",{className:"row"},l.a.createElement("div",{className:"col"},j&&l.a.createElement("a",{href:j,target:"_blank",rel:"noreferrer noopener"},l.a.createElement(w,null),"Edit this page")),(k||C)&&l.a.createElement("div",{className:"col text--right"},l.a.createElement("em",null,l.a.createElement("small",null,"Last updated"," ",k&&l.a.createElement(l.a.Fragment,null,"on"," ",l.a.createElement("time",{dateTime:new Date(1e3*k).toISOString(),className:y.a.docLastUpdatedAt},new Date(1e3*k).toLocaleDateString()),C&&" "),C&&l.a.createElement(l.a.Fragment,null,"by ",l.a.createElement("strong",null,C)),!1))))),l.a.createElement("div",{className:"margin-vert--lg"},l.a.createElement(s,{metadata:m})))),!b&&n.toc&&l.a.createElement("div",{className:"col col--3"},l.a.createElement(N,{toc:n.toc}))))}}}]);
\ No newline at end of file
This diff is collapsed.
/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
This diff is collapsed.
(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{72:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return s})),n.d(t,"metadata",(function(){return r})),n.d(t,"toc",(function(){return c})),n.d(t,"default",(function(){return p}));var a=n(3),l=n(7),i=(n(0),n(88)),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",slug:"/",permalink:"/docs/",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/quickstart.md",version:"current",sidebar:"leftSidebar",next:{title:"HTTP handler",permalink:"/docs/http-handler"}},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:[]}]}],o={toc:c};function p(e){var t=e.components,n=Object(l.a)(e,["components"]);return Object(i.b)("wrapper",Object(a.a)({},o,n,{components:t,mdxType:"MDXLayout"}),Object(i.b)("p",null,"Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/pistache.h>\n")),Object(i.b)("h2",{id:"installing-pistache"},"Installing Pistache"),Object(i.b)("p",null,Object(i.b)("a",{parentName:"p",href:"https://git-scm.com"},"git")," is needed to retrieve the sources. Compiling the sources will require ",Object(i.b)("a",{parentName:"p",href:"https://cmake.org"},"CMake")," to generate build files and a recent compiler that supports C++17."),Object(i.b)("p",null,"If you're on Ubuntu and want to skip the compilation process you can add the official PPA providing nightly builds:"),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-shell"},"sudo add-apt-repository ppa:pistache+team/unstable\nsudo apt update\nsudo apt install libpistache-dev\n")),Object(i.b)("p",null,"Otherwise, here's how to build and install the latest release:"),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-shell"},"git clone https://github.com/pistacheio/pistache.git\ncd pistache\nmeson setup build\nmeson install -C build\n")),Object(i.b)("p",null,"Also, Pistache does not support Windows yet, but should work fine under ",Object(i.b)("a",{parentName:"p",href:"https://docs.microsoft.com/windows/wsl/about"},"WSL"),"."),Object(i.b)("h2",{id:"serving-requests"},"Serving requests"),Object(i.b)("h3",{id:"include"},"Include"),Object(i.b)("p",null,"First, let\u2019s start by including the right header."),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-cpp"},"#include <pistache/endpoint.h>\n")),Object(i.b)("h3",{id:"hello-world"},"Hello world"),Object(i.b)("p",null,"Requests received by Pistache are handled with an ",Object(i.b)("inlineCode",{parentName:"p"},"Http::Handler"),"."),Object(i.b)("p",null,"Let\u2019s start by defining a simple ",Object(i.b)("inlineCode",{parentName:"p"},"HelloHandler"),":"),Object(i.b)("pre",null,Object(i.b)("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')),Object(i.b)("p",null,"Handlers must inherit the ",Object(i.b)("inlineCode",{parentName:"p"},"Http::Handler")," class and at least define the ",Object(i.b)("inlineCode",{parentName:"p"},"onRequest")," member function. They must also define a ",Object(i.b)("inlineCode",{parentName:"p"},"clone()")," member function. Simple handlers can use the special ",Object(i.b)("inlineCode",{parentName:"p"},"HTTP_PROTOTYPE")," macro, passing in the name of the class. The macro will take care of defining the ",Object(i.b)("inlineCode",{parentName:"p"},"clone()")," member function for you."),Object(i.b)("h3",{id:"final-touch"},"Final touch"),Object(i.b)("p",null,"After defining the handler, the server can now be started:"),Object(i.b)("pre",null,Object(i.b)("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")),Object(i.b)("p",null,"For simplicity, you can also use the special ",Object(i.b)("inlineCode",{parentName:"p"},"listenAndServe")," function that will automatically create an endpoint and instantiate your handler:"),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-cpp"},'int main() {\n Http::listenAndServe<HelloHandler>("*:9080");\n}\n')),Object(i.b)("p",null,"And that\u2019s it, now you can fire up your favorite curl request and observe the final result:"),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-shell"},"curl http://localhost:9080/\nHello, World\n")),Object(i.b)("p",null,"Complete code for this example can be found on GitHub: ",Object(i.b)("a",{parentName:"p",href:"https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc"},"examples/hello_server.cc")))}p.isMDXComponent=!0}}]);
\ No newline at end of file
(window.webpackJsonp=window.webpackJsonp||[]).push([[5],{73:function(t,e,i){"use strict";i.r(e),i.d(e,"frontMatter",(function(){return n})),i.d(e,"metadata",(function(){return c})),i.d(e,"toc",(function(){return p})),i.d(e,"default",(function(){return d}));var r=i(3),s=i(7),o=(i(0),i(88)),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",slug:"/rest-description",permalink:"/docs/rest-description",editUrl:"https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/rest-description.md",version:"current"},p=[],a={toc:p};function d(t){var e=t.components,i=Object(s.a)(t,["components"]);return Object(o.b)("wrapper",Object(r.a)({},a,i,{components:e,mdxType:"MDXLayout"}),Object(o.b)("p",null,"Documentation writing for this part is still in progress, please refer to the ",Object(o.b)("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
(window.webpackJsonp=window.webpackJsonp||[]).push([[6],{74:function(e){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
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
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
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([[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([[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.
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
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 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.
!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))}()}();
\ No newline at end of file
(window.webpackJsonp=window.webpackJsonp||[]).push([[7],{75:function(e,t,a){"use strict";a.r(t);var n=a(3),l=a(0),r=a.n(l),i=a(84),c=a(92),s=a(86),m=a(22),o=a(87),u=a(76),d=a.n(u),h=[{title:"Modern API",imageUrl:"img/undraw_futuristic_interface.svg",description:r.a.createElement(r.a.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:r.a.createElement(r.a.Fragment,null,r.a.createElement("ul",null,r.a.createElement("li",null,"A multi-threaded HTTP server to build your APIs"),r.a.createElement("li",null,"An asynchronous HTTP client to request APIs"),r.a.createElement("li",null,"An HTTP router to dispatch requests to C++ functions"),r.a.createElement("li",null,"A REST description DSL to easily define your APIs"),r.a.createElement("li",null,"Type-safe headers and MIME types implementation")))},{title:"Use it",imageUrl:"img/undraw_version_control.svg",description:r.a.createElement(r.a.Fragment,null,r.a.createElement("ul",null,r.a.createElement("li",null,"Clone it on ",r.a.createElement("a",{href:"https://github.com/pistacheio/pistache"},"GitHub")),r.a.createElement("li",null,"Start with the ",r.a.createElement("a",{href:"docs/"},"quickstart")),r.a.createElement("li",null,"Read the full user's ",r.a.createElement("a",{href:"docs/http-handler"},"guide")),r.a.createElement("li",null,"Have issues with it? Fill an ",r.a.createElement("a",{href:"https://github.com/pistacheio/pistache/issues"},"issue"))))}];function E(e){var t=e.imageUrl,a=e.title,n=e.description,l=Object(o.a)(t);return r.a.createElement("div",{className:Object(i.a)("col col--4",d.a.feature)},l&&r.a.createElement("div",{className:"text--center"},r.a.createElement("img",{className:d.a.featureImage,src:l,alt:a})),r.a.createElement("h3",null,a),r.a.createElement("p",null,n))}t.default=function(){var e=Object(m.default)().siteConfig,t=void 0===e?{}:e;return r.a.createElement(c.a,{description:"Description will go into a meta tag in <head />"},r.a.createElement("header",{className:Object(i.a)("hero hero--primary",d.a.heroBanner)},r.a.createElement("div",{className:"container"},r.a.createElement("h1",{className:"hero__title"},t.title),r.a.createElement("p",{className:"hero__subtitle"},t.tagline),r.a.createElement("div",{className:d.a.buttons},r.a.createElement(s.a,{className:Object(i.a)("button button--outline button--secondary button--lg",d.a.getStarted),to:Object(o.a)("docs/")},"Get Started")))),r.a.createElement("main",null,h&&h.length>0&&r.a.createElement("section",{className:d.a.features},r.a.createElement("div",{className:"container"},r.a.createElement("div",{className:"row"},h.map((function(e,t){return r.a.createElement(E,Object(n.a)({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.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
(window.webpackJsonp=window.webpackJsonp||[]).push([[9],{78:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return s})),n.d(t,"toc",(function(){return c})),n.d(t,"default",(function(){return p}));var a=n(3),r=n(7),o=(n(0),n(88)),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",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",sidebar:"leftSidebar",previous:{title:"HTTP handler",permalink:"/docs/http-handler"},next:{title:"Headers",permalink:"/docs/headers"}},c=[],l={toc:c};function p(e){var t=e.components,n=Object(r.a)(e,["components"]);return Object(o.b)("wrapper",Object(a.a)({},l,n,{components:t,mdxType:"MDXLayout"}),Object(o.b)("p",null,"Interfaces provided by Pistaches are ",Object(o.b)("em",{parentName:"p"},"asynchronous")," and ",Object(o.b)("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 ",Object(o.b)("em",{parentName:"p"},"asynchronous calls"),"."),Object(o.b)("p",null,"An example of such a call is the ",Object(o.b)("inlineCode",{parentName:"p"},"send()")," function provided by the ",Object(o.b)("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 ",Object(o.b)("inlineCode",{parentName:"p"},"Promise"),"."),Object(o.b)("p",null,"A ",Object(o.b)("inlineCode",{parentName:"p"},"Promise")," is the Pistache\u2019s implementation of the ",Object(o.b)("a",{parentName:"p",href:"https://promisesaplus.com"},"Promises/A+")," standard available in many JavaScript implementations. Simply put, during an asynchronous call, a ",Object(o.b)("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 ",Object(o.b)("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 ",Object(o.b)("inlineCode",{parentName:"p"},"Promise")," to execute a callback when the result becomes available (when the ",Object(o.b)("inlineCode",{parentName:"p"},"Promise")," has been resolved or fulfilled)."),Object(o.b)("pre",null,Object(o.b)("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')),Object(o.b)("p",null,"The ",Object(o.b)("inlineCode",{parentName:"p"},"then()")," member is used to attach a callback to the ",Object(o.b)("inlineCode",{parentName:"p"},"Promise"),". The first argument is a callable that will be called when the ",Object(o.b)("inlineCode",{parentName:"p"},"Promise")," has been ",Object(o.b)("strong",{parentName:"p"},"succesfully")," resolved. If, for some reason, an error occurs during the asynchronous operation, a ",Object(o.b)("inlineCode",{parentName:"p"},"Promise")," can be ",Object(o.b)("strong",{parentName:"p"},"rejected")," and will then fail. In this case, the second callable will be called. ",Object(o.b)("inlineCode",{parentName:"p"},"Async::NoExcept")," is a special callback that will call ",Object(o.b)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/error/terminate"},Object(o.b)("inlineCode",{parentName:"a"},"std::terminate()"))," if the promise failed. This is the equivalent of the ",Object(o.b)("inlineCode",{parentName:"p"},"noexcept")," keyword."),Object(o.b)("p",null,"Other generic callbacks can also be used in this case:"),Object(o.b)("ul",null,Object(o.b)("li",{parentName:"ul"},Object(o.b)("inlineCode",{parentName:"li"},"Async::IgnoreException")," will simply ignore the exception and let the program continue"),Object(o.b)("li",{parentName:"ul"},Object(o.b)("inlineCode",{parentName:"li"},"Async::Throw"),' will "rethrow" the exception up to an eventual promise call-chain. This has the same effect than the ',Object(o.b)("inlineCode",{parentName:"li"},"throw")," keyword, except that it is suitable for promises")),Object(o.b)("p",null,"Exceptions in promises callbacks are propagated through an ",Object(o.b)("inlineCode",{parentName:"p"},"exception_ptr"),". Promises can also be chained together to create a whole asynchronous pipeline:"),Object(o.b)("pre",null,Object(o.b)("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')),Object(o.b)("p",null,"Line 5 will propagate the exception if ",Object(o.b)("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.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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