Commit e3647648 authored by kiplingw's avatar kiplingw

deploy: 1b96493e

parent 20474c40
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Page Not Found | Pistache</title><meta data-react-helmet="true" property="og:title" content="Page Not Found | Pistache"><meta data-react-helmet="true" property="og:url" content="https://pistache.io/404.html"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_tag" content="default"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/404.html"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/404.html" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/404.html" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Page Not Found | Pistache</title><meta data-react-helmet="true" property="og:title" content="Page Not Found | Pistache"><meta data-react-helmet="true" property="og:url" content="https://pistache.io/404.html"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_tag" content="default"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/404.html"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/404.html" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/404.html" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a class="navbar__item navbar__link" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> <div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a class="navbar__item navbar__link" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Asynchronous HTTP programming | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/asynchronous-http-programming"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Asynchronous HTTP programming | Pistache"><meta data-react-helmet="true" name="description" content="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."><meta data-react-helmet="true" property="og:description" content="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."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/asynchronous-http-programming"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/asynchronous-http-programming" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/asynchronous-http-programming" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Asynchronous HTTP programming | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/asynchronous-http-programming"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Asynchronous HTTP programming | Pistache"><meta data-react-helmet="true" name="description" content="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."><meta data-react-helmet="true" property="og:description" content="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."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/asynchronous-http-programming"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/asynchronous-http-programming" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/asynchronous-http-programming" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">Asynchronous HTTP programming</h1></header><div class="markdown"><p>Interfaces provided by Pistaches are <em>asynchronous</em> and <em>non-blocking</em>. 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 <em>asynchronous calls</em>.</p><p>An example of such a call is the <code>send()</code> function provided by the <code>ResponseWriter</code> 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 <code>Promise</code>.</p><p>A <code>Promise</code> is the Pistache’s implementation of the <a href="https://promisesaplus.com" target="_blank" rel="noopener noreferrer">Promises/A+</a> standard available in many JavaScript implementations. Simply put, during an asynchronous call, a <code>Promise</code> separates the launch of an asynchronous operation from the retrieval of its result. While the asynchronous might still be running, a <code>Promise&lt;T&gt;</code> is directly returned to the caller to retrieve the final result when it becomes available. A so called continuation can be attach to a <code>Promise</code> to execute a callback when the result becomes available (when the <code>Promise</code> has been resolved or fulfilled).</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> res </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;Hello World&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">res</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">ssize_t bytes</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cout </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> bytes </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot; bytes have been sent\n&quot;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">NoExcept</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>then()</code> member is used to attach a callback to the <code>Promise</code>. The first argument is a callable that will be called when the <code>Promise</code> has been <strong>succesfully</strong> resolved. If, for some reason, an error occurs during the asynchronous operation, a <code>Promise</code> can be <strong>rejected</strong> and will then fail. In this case, the second callable will be called. <code>Async::NoExcept</code> is a special callback that will call <a href="https://en.cppreference.com/w/cpp/error/terminate" target="_blank" rel="noopener noreferrer"><code>std::terminate()</code></a> if the promise failed. This is the equivalent of the <code>noexcept</code> keyword.</p><p>Other generic callbacks can also be used in this case:</p><ul><li><code>Async::IgnoreException</code> will simply ignore the exception and let the program continue</li><li><code>Async::Throw</code> will &quot;rethrow&quot; the exception up to an eventual promise call-chain. This has the same effect than the <code>throw</code> keyword, except that it is suitable for promises</li></ul><p>Exceptions in promises callbacks are propagated through an <code>exception_ptr</code>. Promises can also be chained together to create a whole asynchronous pipeline:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> fetchOp </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">fetchDatabase</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">fetchOp</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> User</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> user</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">return</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">fetchUserInfo</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">user</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Throw</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> UserInfo</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> info</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cout </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;User name = &quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> info</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">name </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&#x27;\n&#x27;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">exception_ptr ptr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cerr </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;An exception occured during user retrieval\n&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Line 5 will propagate the exception if <code>fetchDatabase()</code> failed and rejected the promise.</p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/asynchronous-http-programming.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/http-handler"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« HTTP handler</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/headers"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Headers »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> <div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">Asynchronous HTTP programming</h1></header><div class="markdown"><p>Interfaces provided by Pistaches are <em>asynchronous</em> and <em>non-blocking</em>. 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 <em>asynchronous calls</em>.</p><p>An example of such a call is the <code>send()</code> function provided by the <code>ResponseWriter</code> 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 <code>Promise</code>.</p><p>A <code>Promise</code> is the Pistache’s implementation of the <a href="https://promisesaplus.com" target="_blank" rel="noopener noreferrer">Promises/A+</a> standard available in many JavaScript implementations. Simply put, during an asynchronous call, a <code>Promise</code> separates the launch of an asynchronous operation from the retrieval of its result. While the asynchronous might still be running, a <code>Promise&lt;T&gt;</code> is directly returned to the caller to retrieve the final result when it becomes available. A so called continuation can be attach to a <code>Promise</code> to execute a callback when the result becomes available (when the <code>Promise</code> has been resolved or fulfilled).</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> res </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;Hello World&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">res</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">ssize_t bytes</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cout </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> bytes </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot; bytes have been sent\n&quot;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">NoExcept</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>then()</code> member is used to attach a callback to the <code>Promise</code>. The first argument is a callable that will be called when the <code>Promise</code> has been <strong>succesfully</strong> resolved. If, for some reason, an error occurs during the asynchronous operation, a <code>Promise</code> can be <strong>rejected</strong> and will then fail. In this case, the second callable will be called. <code>Async::NoExcept</code> is a special callback that will call <a href="https://en.cppreference.com/w/cpp/error/terminate" target="_blank" rel="noopener noreferrer"><code>std::terminate()</code></a> if the promise failed. This is the equivalent of the <code>noexcept</code> keyword.</p><p>Other generic callbacks can also be used in this case:</p><ul><li><code>Async::IgnoreException</code> will simply ignore the exception and let the program continue</li><li><code>Async::Throw</code> will &quot;rethrow&quot; the exception up to an eventual promise call-chain. This has the same effect than the <code>throw</code> keyword, except that it is suitable for promises</li></ul><p>Exceptions in promises callbacks are propagated through an <code>exception_ptr</code>. Promises can also be chained together to create a whole asynchronous pipeline:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> fetchOp </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">fetchDatabase</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">fetchOp</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> User</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> user</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">return</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">fetchUserInfo</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">user</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Throw</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">then</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> UserInfo</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> info</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cout </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;User name = &quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> info</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">name </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&#x27;\n&#x27;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">exception_ptr ptr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">cerr </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;An exception occured during user retrieval\n&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Line 5 will propagate the exception if <code>fetchDatabase()</code> failed and rejected the promise.</p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/asynchronous-http-programming.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/http-handler"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« HTTP handler</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/headers"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Headers »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Headers | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/headers"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Headers | Pistache"><meta data-react-helmet="true" name="description" content="Overview"><meta data-react-helmet="true" property="og:description" content="Overview"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/headers"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/headers" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/headers" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Headers | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/headers"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Headers | Pistache"><meta data-react-helmet="true" name="description" content="Overview"><meta data-react-helmet="true" property="og:description" content="Overview"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/headers"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/headers" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/headers" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">parse</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> pos </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">find</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&#x27;.&#x27;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">if</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">pos </span><span class="token operator" style="color:rgb(137, 221, 255)">!=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">npos</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> minor </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">stoi</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">substr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">0</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> pos</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> major </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">stoi</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">substr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">pos </span><span class="token operator" style="color:rgb(137, 221, 255)">+</span><span class="token plain"> </span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block"> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">parse</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> pos </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">find</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&#x27;.&#x27;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">if</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">pos </span><span class="token operator" style="color:rgb(137, 221, 255)">!=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">npos</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> minor </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">stoi</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">substr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">0</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> pos</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> major </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">stoi</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">substr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">pos </span><span class="token operator" style="color:rgb(137, 221, 255)">+</span><span class="token plain"> </span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block">
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">write</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ostream</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> os</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> os </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> minor </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;.&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> major</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">private</span><span class="token operator" style="color:rgb(137, 221, 255)">:</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> minor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> major</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>And that’s it. Now all we have to do is registering the header to the registry system:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Registry</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">registerHeader</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">XProtocolVersion</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Header instantation</h5></div><div class="admonition-content"><p>You should always provide a default constructor for your header so that it can be instantiated by the registry system</p></div></div><p>Now, the <code>XProtocolVersion</code> can be retrieved and added like any other header in the <code>Header::Collection</code> class.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Unknown headers</h5></div><div class="admonition-content"><p>Headers that are not known to the registry system are stored as a raw pair of strings in the <code>Collection</code> class. <code>getRaw()</code> can be used to retrieve a raw header:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> myHeader </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">getRaw</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;x-raw-header&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">myHeader</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">name</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// x-raw-header</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">myHeader</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">value</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// returns the value of the header as a string</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="mime-types"></a>MIME types<a class="hash-link" href="#mime-types" title="Direct link to heading">#</a></h2><p><a href="https://en.wikipedia.org/wiki/Media_type" target="_blank" rel="noopener noreferrer">MIME Types</a> (or Media Type) are also fully typed. Such types are for example used in an HTTP request or response to describe the data contained in the body of the message (<code>Content-Type</code> header, …) and are composed of a <em>type</em>, <em>subtype</em>, and optional <em>suffix</em> and parameters.</p><p>MIME Types are represented by the <code>Mime::MediaType</code> class, implemented in the <code>mime.h</code> header. A MIME type can be directly constructed from a string:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">fromString</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;application/json&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>However, to enforce type-safety, common types are all represented as enumerations:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token function" style="color:rgb(130, 170, 255)">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Type</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Subtype</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>To avoid such a typing pain, a <code>MIME</code> macro is also provided:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>For suffix MIMEs, use the special <code>MIME3</code> macro:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME3</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Zip</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>If you like typing, you can also use the long form:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token function" style="color:rgb(130, 170, 255)">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Type</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Subtype</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Suffix</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Zip</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>toString()</code> function can be used to get the string representation of a given MIME type:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Html</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">toString</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// text/html</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/headers.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/asynchronous-http-programming"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Asynchronous HTTP programming</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/routing"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Routing »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#overview" class="table-of-contents__link">Overview</a></li><li><a href="#defining-your-own-header" class="table-of-contents__link">Defining your own header</a></li><li><a href="#mime-types" class="table-of-contents__link">MIME types</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">write</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ostream</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> os</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> os </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> minor </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;.&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> major</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">private</span><span class="token operator" style="color:rgb(137, 221, 255)">:</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> minor</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> major</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>And that’s it. Now all we have to do is registering the header to the registry system:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Registry</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">registerHeader</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">XProtocolVersion</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Header instantation</h5></div><div class="admonition-content"><p>You should always provide a default constructor for your header so that it can be instantiated by the registry system</p></div></div><p>Now, the <code>XProtocolVersion</code> can be retrieved and added like any other header in the <code>Header::Collection</code> class.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Unknown headers</h5></div><div class="admonition-content"><p>Headers that are not known to the registry system are stored as a raw pair of strings in the <code>Collection</code> class. <code>getRaw()</code> can be used to retrieve a raw header:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> myHeader </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">getRaw</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;x-raw-header&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">myHeader</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">name</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// x-raw-header</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">myHeader</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">value</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// returns the value of the header as a string</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="mime-types"></a>MIME types<a class="hash-link" href="#mime-types" title="Direct link to heading">#</a></h2><p><a href="https://en.wikipedia.org/wiki/Media_type" target="_blank" rel="noopener noreferrer">MIME Types</a> (or Media Type) are also fully typed. Such types are for example used in an HTTP request or response to describe the data contained in the body of the message (<code>Content-Type</code> header, …) and are composed of a <em>type</em>, <em>subtype</em>, and optional <em>suffix</em> and parameters.</p><p>MIME Types are represented by the <code>Mime::MediaType</code> class, implemented in the <code>mime.h</code> header. A MIME type can be directly constructed from a string:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">fromString</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;application/json&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>However, to enforce type-safety, common types are all represented as enumerations:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token function" style="color:rgb(130, 170, 255)">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Type</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Subtype</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>To avoid such a typing pain, a <code>MIME</code> macro is also provided:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>For suffix MIMEs, use the special <code>MIME3</code> macro:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME3</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Zip</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>If you like typing, you can also use the long form:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token function" style="color:rgb(130, 170, 255)">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Type</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Application</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Subtype</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Json</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Suffix</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Zip</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>toString()</code> function can be used to get the string representation of a given MIME type:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> m1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Html</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">m1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">toString</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// text/html</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/headers.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/asynchronous-http-programming"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Asynchronous HTTP programming</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/routing"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Routing »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#overview" class="table-of-contents__link">Overview</a></li><li><a href="#defining-your-own-header" class="table-of-contents__link">Defining your own header</a></li><li><a href="#mime-types" class="table-of-contents__link">MIME types</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">HTTP handler | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/http-handler"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="HTTP handler | Pistache"><meta data-react-helmet="true" name="description" content="Requests that are received by Pistache are handled by a special class called Http::Handler. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection."><meta data-react-helmet="true" property="og:description" content="Requests that are received by Pistache are handled by a special class called Http::Handler. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/http-handler"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/http-handler" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/http-handler" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">HTTP handler | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/http-handler"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="HTTP handler | Pistache"><meta data-react-helmet="true" name="description" content="Requests that are received by Pistache are handled by a special class called Http::Handler. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection."><meta data-react-helmet="true" property="og:description" content="Requests that are received by Pistache are handled by a special class called Http::Handler. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/http-handler"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/http-handler" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/http-handler" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">HTTP handler</h1></header><div class="markdown"><p>Requests that are received by Pistache are handled by a special class called <code>Http::Handler</code>. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection.</p><p>The <code>onRequest()</code> function must be overriden. This function is called whenever Pistache received data and correctly parsed it as an HTTP request.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">virtual</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onRequest</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The first argument is an object of type <code>Http::Request</code> representing the request itself. It contains a bunch of informations including:</p><ul><li>The resource associated to the request</li><li>The query parameters</li><li>The headers</li><li>The body of the request</li></ul><p>The <code>Request</code> object gives a read-only access to these informations. You can access them through a couple of getters but can not modify them. An HTTP request is <strong>immutable</strong>.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="sending-a-response"></a>Sending a response<a class="hash-link" href="#sending-a-response" title="Direct link to heading">#</a></h2><p><code>ResponseWriter</code> is an object from which the final HTTP response is sent to the client. The <code>onRequest()</code> function does not return anything (<code>void</code>). Instead, the response is sent through the <code>ResponseWriter</code> class. This class provides a bunch of <code>send()</code> function overloads to send the response:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>You can use this overload to send a response with an empty body and a given HTTP Code (e.g <code>Http::Code::Ok</code>)</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> body</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">MediaType</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This overload can be used to send a response with static, fixed-size content (body). A MIME type can also be specified, which will be sent through the <code>Content-Type</code> header.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">template</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">size_t N</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">char</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">arr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token plain">N</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">MediaType</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This version can also be used to send a fixed-size response with a body except that it does not need to construct a string (no memory is allocated). The size of the content is directly deduced by the compiler. This version only works with raw string literals.</p><p>These functions are asynchronous, meaning that they do not return a plain old <code>ssize_t</code> value indicating the number of bytes being sent, but instead a <code>Promise</code> that will be fulfilled later on. See the next section for more details on asynchronous programming with Pistache.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="response-streaming"></a>Response streaming<a class="hash-link" href="#response-streaming" title="Direct link to heading">#</a></h2><p>Sometimes, content that is to be sent back to the user can not be known in advance, thus the length can not be determined in advance. For that matter, the HTTP specification defines a special data-transfer mechanism called <a href="https://tools.ietf.org/html/rfc7230#section-4.1" target="_blank" rel="noopener noreferrer">chunked encoding</a> where data is sent in a series of <em>chunks</em>. This mechanism uses the <code>Transfer-Encoding</code> HTTP header in place of the <code>Content-Length</code> one.</p><p>To stream content, Pistache provides a special <code>ResponseStream</code> class. To get a <code>ResponseStream</code> from a <code>ResponseWriter</code>, call the <code>stream()</code> member function:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> stream </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">stream</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>To initate a stream, you have to pass the HTTP status code to the stream function (here <code>Http::Code::Ok</code> or <code>HTTP 200</code>). The <code>ResponseStream</code> class provides an <code>iostream</code> like interface that overloads the <code>&lt;&lt;</code> operator.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;PO&quot;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;NG&quot;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The first line will write a chunk of size 2 with the content <em>PO</em> to the stream&#x27;s buffer. The second line will write a second chunk of size 2 with the content <em>NG</em>. To end the stream and flush the content, use the special <code>ends</code> marker:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> ends</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>ends</code> marker will write the last chunk of size 0 and send the final data over the network. To simply flush the stream&#x27;s buffer without ending the stream, you can use the <code>flush</code> marker:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> flush</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-caution alert alert--warning"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>Headers writing</h5></div><div class="admonition-content"><p>After starting a stream, headers become immutable. They must be written to the response before creating a <code>ResponseStream</code>:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">add</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Server</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;lys&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">add</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ContentType</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Plain</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block"> <div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">HTTP handler</h1></header><div class="markdown"><p>Requests that are received by Pistache are handled by a special class called <code>Http::Handler</code>. This class declares a bunch of virtual methods that can be overriden to handle special events that occur on the socket and/or connection.</p><p>The <code>onRequest()</code> function must be overriden. This function is called whenever Pistache received data and correctly parsed it as an HTTP request.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">virtual</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onRequest</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The first argument is an object of type <code>Http::Request</code> representing the request itself. It contains a bunch of informations including:</p><ul><li>The resource associated to the request</li><li>The query parameters</li><li>The headers</li><li>The body of the request</li></ul><p>The <code>Request</code> object gives a read-only access to these informations. You can access them through a couple of getters but can not modify them. An HTTP request is <strong>immutable</strong>.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="sending-a-response"></a>Sending a response<a class="hash-link" href="#sending-a-response" title="Direct link to heading">#</a></h2><p><code>ResponseWriter</code> is an object from which the final HTTP response is sent to the client. The <code>onRequest()</code> function does not return anything (<code>void</code>). Instead, the response is sent through the <code>ResponseWriter</code> class. This class provides a bunch of <code>send()</code> function overloads to send the response:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>You can use this overload to send a response with an empty body and a given HTTP Code (e.g <code>Http::Code::Ok</code>)</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> body</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType </span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">MediaType</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This overload can be used to send a response with static, fixed-size content (body). A MIME type can also be specified, which will be sent through the <code>Content-Type</code> header.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">template</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">size_t N</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Async</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Promise</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">ssize_t</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Code code</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">char</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">arr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">[</span><span class="token plain">N</span><span class="token punctuation" style="color:rgb(199, 146, 234)">]</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">MediaType</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> mime </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Mime</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">MediaType</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This version can also be used to send a fixed-size response with a body except that it does not need to construct a string (no memory is allocated). The size of the content is directly deduced by the compiler. This version only works with raw string literals.</p><p>These functions are asynchronous, meaning that they do not return a plain old <code>ssize_t</code> value indicating the number of bytes being sent, but instead a <code>Promise</code> that will be fulfilled later on. See the next section for more details on asynchronous programming with Pistache.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="response-streaming"></a>Response streaming<a class="hash-link" href="#response-streaming" title="Direct link to heading">#</a></h2><p>Sometimes, content that is to be sent back to the user can not be known in advance, thus the length can not be determined in advance. For that matter, the HTTP specification defines a special data-transfer mechanism called <a href="https://tools.ietf.org/html/rfc7230#section-4.1" target="_blank" rel="noopener noreferrer">chunked encoding</a> where data is sent in a series of <em>chunks</em>. This mechanism uses the <code>Transfer-Encoding</code> HTTP header in place of the <code>Content-Length</code> one.</p><p>To stream content, Pistache provides a special <code>ResponseStream</code> class. To get a <code>ResponseStream</code> from a <code>ResponseWriter</code>, call the <code>stream()</code> member function:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> stream </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">stream</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>To initate a stream, you have to pass the HTTP status code to the stream function (here <code>Http::Code::Ok</code> or <code>HTTP 200</code>). The <code>ResponseStream</code> class provides an <code>iostream</code> like interface that overloads the <code>&lt;&lt;</code> operator.</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;PO&quot;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;NG&quot;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The first line will write a chunk of size 2 with the content <em>PO</em> to the stream&#x27;s buffer. The second line will write a second chunk of size 2 with the content <em>NG</em>. To end the stream and flush the content, use the special <code>ends</code> marker:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> ends</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>ends</code> marker will write the last chunk of size 0 and send the final data over the network. To simply flush the stream&#x27;s buffer without ending the stream, you can use the <code>flush</code> marker:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> flush</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-caution alert alert--warning"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>Headers writing</h5></div><div class="admonition-content"><p>After starting a stream, headers become immutable. They must be written to the response before creating a <code>ResponseStream</code>:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">headers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">add</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Server</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;lys&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">add</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">Header</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ContentType</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token function" style="color:rgb(130, 170, 255)">MIME</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Text</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Plain</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block">
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> stream </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">stream</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;PO&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;NG&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> ends</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="static-file-serving"></a>Static file serving<a class="hash-link" href="#static-file-serving" title="Direct link to heading">#</a></h2><p>In addition to text content serving, Pistache provides a way to serve static files through the <code>Http::serveFile</code> function:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">if</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">resource</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">==</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/doc&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">method </span><span class="token operator" style="color:rgb(137, 221, 255)">==</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Method</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">serveFile</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;README.md&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Return value</h5></div><div class="admonition-content"><p><code>serveFile</code> also returns a <code>Promise</code> representing the total number of bytes being sent to the wire</p></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="controlling-timeout"></a>Controlling timeout<a class="hash-link" href="#controlling-timeout" title="Direct link to heading">#</a></h2><p>Sometimes, you might require to timeout after a certain amount of time. For example, if you are designing an HTTP API with soft real-time constraints, you will have a time constraint to send a response back to the client. That is why Pistache provides the ability to control the timeout on a per-request basis. To arm a timeout on a response, you can use the <code>timeoutAfter()</code> member function directly on the <code>ResponseWriter</code> object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">timeoutAfter</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">chrono</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">milliseconds</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">500</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This will trigger a timeout if a response has not been sent within 500 milliseconds. <code>timeoutAfter</code> accepts any kind of duration.</p><p>When a timeout triggers, the <code>onTimeout()</code> function from your handler will be called. By default, this method does nothing. If you want to handle your timeout properly, you should then override this function inside your own handler:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onTimeout</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter writer</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">No_Content</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>Request</code> object that is passed to the <code>onTimeout</code> is the exact same request that triggered the timeout. The <code>ResponseWriter</code> is a complete new writer object.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>ResponseWriter state</h5></div><div class="admonition-content"><p>Since the <code>ResponseWriter</code> object is a complete new object, state is not preserved with the <code>ResponseWriter</code> from the <code>onRequest()</code> callback, which means that you will have to write the complete response again, including headers and cookies.</p></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/http-handler.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Getting started</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/asynchronous-http-programming"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Asynchronous HTTP programming »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#sending-a-response" class="table-of-contents__link">Sending a response</a></li><li><a href="#response-streaming" class="table-of-contents__link">Response streaming</a></li><li><a href="#static-file-serving" class="table-of-contents__link">Static file serving</a></li><li><a href="#controlling-timeout" class="table-of-contents__link">Controlling timeout</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> stream </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">stream</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">stream </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;PO&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;NG&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;&lt;</span><span class="token plain"> ends</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="static-file-serving"></a>Static file serving<a class="hash-link" href="#static-file-serving" title="Direct link to heading">#</a></h2><p>In addition to text content serving, Pistache provides a way to serve static files through the <code>Http::serveFile</code> function:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">if</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">resource</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">==</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/doc&quot;</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">method </span><span class="token operator" style="color:rgb(137, 221, 255)">==</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Method</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">serveFile</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;README.md&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Return value</h5></div><div class="admonition-content"><p><code>serveFile</code> also returns a <code>Promise</code> representing the total number of bytes being sent to the wire</p></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="controlling-timeout"></a>Controlling timeout<a class="hash-link" href="#controlling-timeout" title="Direct link to heading">#</a></h2><p>Sometimes, you might require to timeout after a certain amount of time. For example, if you are designing an HTTP API with soft real-time constraints, you will have a time constraint to send a response back to the client. That is why Pistache provides the ability to control the timeout on a per-request basis. To arm a timeout on a response, you can use the <code>timeoutAfter()</code> member function directly on the <code>ResponseWriter</code> object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">timeoutAfter</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">chrono</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">milliseconds</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">500</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>This will trigger a timeout if a response has not been sent within 500 milliseconds. <code>timeoutAfter</code> accepts any kind of duration.</p><p>When a timeout triggers, the <code>onTimeout()</code> function from your handler will be called. By default, this method does nothing. If you want to handle your timeout properly, you should then override this function inside your own handler:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onTimeout</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter writer</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">No_Content</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>The <code>Request</code> object that is passed to the <code>onTimeout</code> is the exact same request that triggered the timeout. The <code>ResponseWriter</code> is a complete new writer object.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>ResponseWriter state</h5></div><div class="admonition-content"><p>Since the <code>ResponseWriter</code> object is a complete new object, state is not preserved with the <code>ResponseWriter</code> from the <code>onRequest()</code> callback, which means that you will have to write the complete response again, including headers and cookies.</p></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/http-handler.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Getting started</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/asynchronous-http-programming"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Asynchronous HTTP programming »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#sending-a-response" class="table-of-contents__link">Sending a response</a></li><li><a href="#response-streaming" class="table-of-contents__link">Response streaming</a></li><li><a href="#static-file-serving" class="table-of-contents__link">Static file serving</a></li><li><a href="#controlling-timeout" class="table-of-contents__link">Controlling timeout</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Getting started | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Getting started | Pistache"><meta data-react-helmet="true" name="description" content="Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."><meta data-react-helmet="true" property="og:description" content="Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Getting started | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Getting started | Pistache"><meta data-react-helmet="true" name="description" content="Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."><meta data-react-helmet="true" property="og:description" content="Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onRequest</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;Hello, World\n&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Handlers must inherit the <code>Http::Handler</code> class and at least define the <code>onRequest</code> member function. They must also define a <code>clone()</code> member function. Simple handlers can use the special <code>HTTP_PROTOTYPE</code> macro, passing in the name of the class. The macro will take care of defining the <code>clone()</code> member function for you.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="final-touch"></a>Final touch<a class="hash-link" href="#final-touch" title="Direct link to heading">#</a></h3><p>After defining the handler, the server can now be started:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">main</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Address </span><span class="token function" style="color:rgb(130, 170, 255)">addr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Ipv4</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">any</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">Port</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">9080</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block"> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">onRequest</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">send</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Code</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Ok</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;Hello, World\n&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Handlers must inherit the <code>Http::Handler</code> class and at least define the <code>onRequest</code> member function. They must also define a <code>clone()</code> member function. Simple handlers can use the special <code>HTTP_PROTOTYPE</code> macro, passing in the name of the class. The macro will take care of defining the <code>clone()</code> member function for you.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="final-touch"></a>Final touch<a class="hash-link" href="#final-touch" title="Direct link to heading">#</a></h3><p>After defining the handler, the server can now be started:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">main</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Address </span><span class="token function" style="color:rgb(130, 170, 255)">addr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Ipv4</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">any</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">Port</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">9080</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block">
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> opts </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Endpoint</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">options</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">threads</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Endpoint </span><span class="token function" style="color:rgb(130, 170, 255)">server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">addr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">init</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">opts</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">setHandler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">make_handler</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">HelloHandler</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">serve</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>For simplicity, you can also use the special <code>listenAndServe</code> function that will automatically create an endpoint and instantiate your handler:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">main</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">listenAndServe</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">HelloHandler</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;*:9080&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>And that’s it, now you can fire up your favorite curl request and observe the final result:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly shell"><div tabindex="0" class="prism-code language-shell codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token function" style="color:rgb(130, 170, 255)">curl</span><span class="token plain"> http://localhost:9080/</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Hello, World</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Complete code for this example can be found on GitHub: <a href="https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc" target="_blank" rel="noopener noreferrer">examples/hello_server.cc</a></p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/quickstart.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/http-handler"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">HTTP handler »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#installing-pistache" class="table-of-contents__link">Installing Pistache</a></li><li><a href="#serving-requests" class="table-of-contents__link">Serving requests</a><ul><li><a href="#include" class="table-of-contents__link">Include</a></li><li><a href="#hello-world" class="table-of-contents__link">Hello world</a></li><li><a href="#final-touch" class="table-of-contents__link">Final touch</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> opts </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Endpoint</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">options</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">threads</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Endpoint </span><span class="token function" style="color:rgb(130, 170, 255)">server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">addr</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">init</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">opts</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">setHandler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">make_handler</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">HelloHandler</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> server</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">serve</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>For simplicity, you can also use the special <code>listenAndServe</code> function that will automatically create an endpoint and instantiate your handler:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">int</span><span class="token plain"> </span><span class="token function" style="color:rgb(130, 170, 255)">main</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">listenAndServe</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">HelloHandler</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;*:9080&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>And that’s it, now you can fire up your favorite curl request and observe the final result:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly shell"><div tabindex="0" class="prism-code language-shell codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token function" style="color:rgb(130, 170, 255)">curl</span><span class="token plain"> http://localhost:9080/</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Hello, World</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Complete code for this example can be found on GitHub: <a href="https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc" target="_blank" rel="noopener noreferrer">examples/hello_server.cc</a></p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/quickstart.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/http-handler"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">HTTP handler »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#installing-pistache" class="table-of-contents__link">Installing Pistache</a></li><li><a href="#serving-requests" class="table-of-contents__link">Serving requests</a><ul><li><a href="#include" class="table-of-contents__link">Include</a></li><li><a href="#hello-world" class="table-of-contents__link">Hello world</a></li><li><a href="#final-touch" class="table-of-contents__link">Final touch</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">REST description | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/rest-description"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="REST description | Pistache"><meta data-react-helmet="true" name="description" content="Documentation writing for this part is still in progress, please refer to the restdescription example."><meta data-react-helmet="true" property="og:description" content="Documentation writing for this part is still in progress, please refer to the restdescription example."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/rest-description"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/rest-description" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/rest-description" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">REST description | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/rest-description"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="REST description | Pistache"><meta data-react-helmet="true" name="description" content="Documentation writing for this part is still in progress, please refer to the restdescription example."><meta data-react-helmet="true" property="og:description" content="Documentation writing for this part is still in progress, please refer to the restdescription example."><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/rest-description"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/rest-description" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/rest-description" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><main class="docMainContainer_3ufF docMainContainerEnhanced_3NYZ"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">REST description</h1></header><div class="markdown"><p>Documentation writing for this part is still in progress, please refer to the <a href="https://github.com/pistacheio/pistache/blob/master/examples/rest_description.cc" target="_blank" rel="noopener noreferrer">rest_description</a> example.</p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/rest-description.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> <div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><main class="docMainContainer_3ufF docMainContainerEnhanced_3NYZ"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">REST description</h1></header><div class="markdown"><p>Documentation writing for this part is still in progress, please refer to the <a href="https://github.com/pistacheio/pistache/blob/master/examples/rest_description.cc" target="_blank" rel="noopener noreferrer">rest_description</a> example.</p></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/rest-description.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Routing | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/routing"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Routing | Pistache"><meta data-react-helmet="true" name="description" content="HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:"><meta data-react-helmet="true" property="og:description" content="HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/routing"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/routing" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/routing" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Routing | Pistache</title><meta data-react-helmet="true" property="og:url" content="https://pistache.io/docs/routing"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_version" content="current"><meta data-react-helmet="true" name="docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:title" content="Routing | Pistache"><meta data-react-helmet="true" name="description" content="HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:"><meta data-react-helmet="true" property="og:description" content="HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/docs/routing"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/routing" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/docs/routing" hreflang="x-default"><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">Routing</h1></header><div class="markdown"><p>HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly javascript"><div tabindex="0" class="prism-code language-javascript codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token constant" style="color:rgb(130, 170, 255)">GET</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">/</span><span class="token plain">users</span><span class="token operator" style="color:rgb(137, 221, 255)">/</span><span class="token number" style="color:rgb(247, 140, 108)">1</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Here, <code>GET</code> is the verb and <code>/users/1</code> is the associated resource.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="http-methods"></a>HTTP methods<a class="hash-link" href="#http-methods" title="Direct link to heading">#</a></h2><p>A bunch of HTTP methods (verbs) are supported by Pistache:</p><ul><li><em>GET</em>: The <code>GET</code> method is used by the client (e.g browser) to retrieve a resource identified by an URI. For example, to retrieve an user identified by an id, a client will issue a <code>GET</code> to the <code>/users/:id</code> Request-URI.</li><li><em>POST</em>: the <code>POST</code> method is used to post or send new information to a certain resource. The server will then read and store the data associated to the request. <code>POST</code> is a common way of transmitting data from an HTML form. <code>POST</code> can also be used to create a new resource or update information of an existing resource. For example, to create a new user, a client will issue a <code>POST</code> to the <code>/users</code> path with the data of the user to create in its body.</li><li><em>PUT</em>: <code>PUT</code> is very similar to <code>POST</code> except that <code>PUT</code> is idempotent, meaning that two requests to the same Request-URI with the same identical content should have the same effect and should produce the same result.</li><li><em>DELETE</em>: the <code>DELETE</code> method is used to delete a resource associated to a given Request-URI. For example, to remove an user, a client might issue a <code>DELETE</code> call to the <code>/users/:id</code> Request-URI.</li></ul><p>To sum up, <code>POST</code> and <code>PUT</code> are used to Create and/or Update, <code>GET</code> is used to Read and <code>DELETE</code> is used to Delete information.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="route-patterns"></a>Route patterns<a class="hash-link" href="#route-patterns" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="static-routes"></a>Static routes<a class="hash-link" href="#static-routes" title="Direct link to heading">#</a></h3><p>Static routes are the simplest ones as they do rely on dynamic parts of the Request-URI. For example <code>/users/all</code> is a static route that will exactly match the <code>/users/all</code> Request-URI.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="dynamic-routes"></a>Dynamic routes<a class="hash-link" href="#dynamic-routes" title="Direct link to heading">#</a></h3><p>However, it is often useful to define routes that have dynamic parts. For example, to retrieve a specific user by its id, the id is needed to query the storage. Dynamic routes thus have parameters that are then matched one by one by the HTTP router. In a dynamic route, parameters are identified by a column <code>:</code></p><p><code>/users/:id</code></p><p>Here, <code>:id</code> is a dynamic parameter. When a request comes in, the router will try to match the <code>:id</code> parameter to the corresponding part of the request. For example, if the server receives a request to <code>/users/13</code>, the router will match the <code>13</code> value to the <code>:id</code> parameter.</p><p>Some parameters, like <code>:id</code> are named. However, Pistache also allows <em>splat</em> (wildcard) parameters, identified by a star <code>*</code>:</p><p><code>/link/*/to/*</code></p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="defining-routes"></a>Defining routes<a class="hash-link" href="#defining-routes" title="Direct link to heading">#</a></h2><p>To define your routes, you first have to instantiate an HTTP router:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Router router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Then, use the <code>Routes::&lt;Method&gt;()</code> functions to add some routes:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/users/all&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">getAllUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Post</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/users/:id&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">getUserId</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/link/*/to/*&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">linkUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p><code>Routes::bind</code> is a special function that will generate a corresponding C++ callback that will then be called by the router if a given route matches the Request-URI.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="callbacks"></a>Callbacks<a class="hash-link" href="#callbacks" title="Direct link to heading">#</a></h3><p>A C++ callback associated to a route must have the following signature:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>A callback can either be a non-static free or member function. For member functions, a pointer to the corresponding instance must be passed to the Routes::bind function so that the router knows on which instance to invoke the member function.</p><p>The first parameter of the callback is <code>Rest::Request</code> and not an <code>Http::Request</code>. A <code>Rest::Request</code> is an <code>Http::Request</code> with additional functions. Named and splat parameters are for example retrieved through this object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">getUserId</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> id </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">param</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;:id&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token keyword" style="font-style:italic">int</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// ...</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block"> <div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper docs-wrapper doc-page"><div class="docPage_31aa"><div class="docSidebarContainer_3Kbt" role="complementary"><div class="sidebar_15mo"><div class="menu menu--responsive thin-scrollbar menu_Bmed"><button aria-label="Open menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_fgN0" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Pistache</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/">Getting started</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/http-handler">HTTP handler</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/asynchronous-http-programming">Asynchronous HTTP programming</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/headers">Headers</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/routing">Routing</a></li></ul></li></ul></div></div></div><main class="docMainContainer_3ufF"><div class="container padding-vert--lg docItemWrapper_3FMP"><div class="row"><div class="col docItemCol_3FnS"><div class="docItemContainer_33ec"><article><header><h1 class="docTitle_3a4h">Routing</h1></header><div class="markdown"><p>HTTP routing consists of binding an HTTP route to a C++ callback. A special component called an HTTP router will be in charge of dispatching HTTP requests to the right C++ callback. A route is composed of an HTTP verb associated to a resource:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly javascript"><div tabindex="0" class="prism-code language-javascript codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token constant" style="color:rgb(130, 170, 255)">GET</span><span class="token plain"> </span><span class="token operator" style="color:rgb(137, 221, 255)">/</span><span class="token plain">users</span><span class="token operator" style="color:rgb(137, 221, 255)">/</span><span class="token number" style="color:rgb(247, 140, 108)">1</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Here, <code>GET</code> is the verb and <code>/users/1</code> is the associated resource.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="http-methods"></a>HTTP methods<a class="hash-link" href="#http-methods" title="Direct link to heading">#</a></h2><p>A bunch of HTTP methods (verbs) are supported by Pistache:</p><ul><li><em>GET</em>: The <code>GET</code> method is used by the client (e.g browser) to retrieve a resource identified by an URI. For example, to retrieve an user identified by an id, a client will issue a <code>GET</code> to the <code>/users/:id</code> Request-URI.</li><li><em>POST</em>: the <code>POST</code> method is used to post or send new information to a certain resource. The server will then read and store the data associated to the request. <code>POST</code> is a common way of transmitting data from an HTML form. <code>POST</code> can also be used to create a new resource or update information of an existing resource. For example, to create a new user, a client will issue a <code>POST</code> to the <code>/users</code> path with the data of the user to create in its body.</li><li><em>PUT</em>: <code>PUT</code> is very similar to <code>POST</code> except that <code>PUT</code> is idempotent, meaning that two requests to the same Request-URI with the same identical content should have the same effect and should produce the same result.</li><li><em>DELETE</em>: the <code>DELETE</code> method is used to delete a resource associated to a given Request-URI. For example, to remove an user, a client might issue a <code>DELETE</code> call to the <code>/users/:id</code> Request-URI.</li></ul><p>To sum up, <code>POST</code> and <code>PUT</code> are used to Create and/or Update, <code>GET</code> is used to Read and <code>DELETE</code> is used to Delete information.</p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="route-patterns"></a>Route patterns<a class="hash-link" href="#route-patterns" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="static-routes"></a>Static routes<a class="hash-link" href="#static-routes" title="Direct link to heading">#</a></h3><p>Static routes are the simplest ones as they do rely on dynamic parts of the Request-URI. For example <code>/users/all</code> is a static route that will exactly match the <code>/users/all</code> Request-URI.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="dynamic-routes"></a>Dynamic routes<a class="hash-link" href="#dynamic-routes" title="Direct link to heading">#</a></h3><p>However, it is often useful to define routes that have dynamic parts. For example, to retrieve a specific user by its id, the id is needed to query the storage. Dynamic routes thus have parameters that are then matched one by one by the HTTP router. In a dynamic route, parameters are identified by a column <code>:</code></p><p><code>/users/:id</code></p><p>Here, <code>:id</code> is a dynamic parameter. When a request comes in, the router will try to match the <code>:id</code> parameter to the corresponding part of the request. For example, if the server receives a request to <code>/users/13</code>, the router will match the <code>13</code> value to the <code>:id</code> parameter.</p><p>Some parameters, like <code>:id</code> are named. However, Pistache also allows <em>splat</em> (wildcard) parameters, identified by a star <code>*</code>:</p><p><code>/link/*/to/*</code></p><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="defining-routes"></a>Defining routes<a class="hash-link" href="#defining-routes" title="Direct link to heading">#</a></h2><p>To define your routes, you first have to instantiate an HTTP router:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Router router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>Then, use the <code>Routes::&lt;Method&gt;()</code> functions to add some routes:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/users/all&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">getAllUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Post</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/users/:id&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">getUserId</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">Get</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token string" style="color:rgb(195, 232, 141)">&quot;/link/*/to/*&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Routes</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">bind</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain">UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">linkUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> </span><span class="token keyword" style="font-style:italic">this</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p><code>Routes::bind</code> is a special function that will generate a corresponding C++ callback that will then be called by the router if a given route matches the Request-URI.</p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="callbacks"></a>Callbacks<a class="hash-link" href="#callbacks" title="Direct link to heading">#</a></h3><p>A C++ callback associated to a route must have the following signature:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>A callback can either be a non-static free or member function. For member functions, a pointer to the corresponding instance must be passed to the Routes::bind function so that the router knows on which instance to invoke the member function.</p><p>The first parameter of the callback is <code>Rest::Request</code> and not an <code>Http::Request</code>. A <code>Rest::Request</code> is an <code>Http::Request</code> with additional functions. Named and splat parameters are for example retrieved through this object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">getUserId</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> id </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">param</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token string" style="color:rgb(195, 232, 141)">&quot;:id&quot;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token keyword" style="font-style:italic">int</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// ...</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain" style="display:inline-block">
</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">linkUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> u1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">splatAt</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">0</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> u2 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">splatAt</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// ...</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>As you can see, parameters are also typed. To cast a parameter to the appropriate type, use the <code>as&lt;T&gt;</code> member template.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Cast safety</h5></div><div class="admonition-content"><p>An exception will be thrown if the parameter can not be casted to the right type</p></div></div><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="installing-the-handler"></a>Installing the handler<a class="hash-link" href="#installing-the-handler" title="Direct link to heading">#</a></h3><p>Once the routes have been defined, the final <code>Http::Handler</code> must be set to the HTTP Endpoint. To retrieve the handler, just call the <code>handler()</code> member function on the router object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">endpoint</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">setHandler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">handler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/routing.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/headers"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Headers</div></a></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#http-methods" class="table-of-contents__link">HTTP methods</a></li><li><a href="#route-patterns" class="table-of-contents__link">Route patterns</a><ul><li><a href="#static-routes" class="table-of-contents__link">Static routes</a></li><li><a href="#dynamic-routes" class="table-of-contents__link">Dynamic routes</a></li></ul></li><li><a href="#defining-routes" class="table-of-contents__link">Defining routes</a><ul><li><a href="#callbacks" class="table-of-contents__link">Callbacks</a></li><li><a href="#installing-the-handler" class="table-of-contents__link">Installing the handler</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> </span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token keyword" style="font-style:italic">void</span><span class="token plain"> UsersApi</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token function" style="color:rgb(130, 170, 255)">linkUsers</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token keyword" style="font-style:italic">const</span><span class="token plain"> Rest</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">Request</span><span class="token operator" style="color:rgb(137, 221, 255)">&amp;</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">,</span><span class="token plain"> Http</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">ResponseWriter response</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:rgb(199, 146, 234)">{</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> u1 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">splatAt</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">0</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token keyword" style="font-style:italic">auto</span><span class="token plain"> u2 </span><span class="token operator" style="color:rgb(137, 221, 255)">=</span><span class="token plain"> request</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">splatAt</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token number" style="color:rgb(247, 140, 108)">1</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token plain">as</span><span class="token operator" style="color:rgb(137, 221, 255)">&lt;</span><span class="token plain">std</span><span class="token operator" style="color:rgb(137, 221, 255)">::</span><span class="token plain">string</span><span class="token operator" style="color:rgb(137, 221, 255)">&gt;</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"> </span><span class="token comment" style="color:rgb(105, 112, 152);font-style:italic">// ...</span><span class="token plain"></span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain"></span><span class="token punctuation" style="color:rgb(199, 146, 234)">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div><p>As you can see, parameters are also typed. To cast a parameter to the appropriate type, use the <code>as&lt;T&gt;</code> member template.</p><div class="admonition admonition-note alert alert--secondary"><div class="admonition-heading"><h5><span class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>Cast safety</h5></div><div class="admonition-content"><p>An exception will be thrown if the parameter can not be casted to the right type</p></div></div><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_2LWZ" id="installing-the-handler"></a>Installing the handler<a class="hash-link" href="#installing-the-handler" title="Direct link to heading">#</a></h3><p>Once the routes have been defined, the final <code>Http::Handler</code> must be set to the HTTP Endpoint. To retrieve the handler, just call the <code>handler()</code> member function on the router object:</p><div class="codeBlockContainer_K1bP"><div class="codeBlockContent_hGly cpp"><div tabindex="0" class="prism-code language-cpp codeBlock_23N8 thin-scrollbar"><div class="codeBlockLines_39YC" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">endpoint</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">setHandler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token plain">router</span><span class="token punctuation" style="color:rgb(199, 146, 234)">.</span><span class="token function" style="color:rgb(130, 170, 255)">handler</span><span class="token punctuation" style="color:rgb(199, 146, 234)">(</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">)</span><span class="token punctuation" style="color:rgb(199, 146, 234)">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_Ue-o">Copy</button></div></div></div></article><div class="margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/pistacheio/pistache/edit/master/pistache.io/docs/routing.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2_ui" aria-label="Edit page"><g><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"></path></g></svg>Edit this page</a></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Docs pages navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/headers"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Headers</div></a></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_35-E thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#http-methods" class="table-of-contents__link">HTTP methods</a></li><li><a href="#route-patterns" class="table-of-contents__link">Route patterns</a><ul><li><a href="#static-routes" class="table-of-contents__link">Static routes</a></li><li><a href="#dynamic-routes" class="table-of-contents__link">Dynamic routes</a></li></ul></li><li><a href="#defining-routes" class="table-of-contents__link">Defining routes</a><ul><li><a href="#callbacks" class="table-of-contents__link">Callbacks</a></li><li><a href="#installing-the-handler" class="table-of-contents__link">Installing the handler</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.75"> <meta name="generator" content="Docusaurus v2.0.0-beta.0">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Pistache Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Pistache</title><meta data-react-helmet="true" property="og:title" content="Pistache"><meta data-react-helmet="true" name="description" content="Description will go into a meta tag in &lt;head /&gt;"><meta data-react-helmet="true" property="og:description" content="Description will go into a meta tag in &lt;head /&gt;"><meta data-react-helmet="true" property="og:url" content="https://pistache.io/"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_tag" content="default"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/" hreflang="x-default"><script data-react-helmet="true">function maybeInsertBanner(){window.__DOCUSAURUS_INSERT_BASEURL_BANNER&&insertBanner()}function insertBanner(){var n=document.getElementById("docusaurus-base-url-issue-banner-container");if(n){n.innerHTML='\n<div id="docusaurus-base-url-issue-banner" style="border: thick solid red; background-color: rgb(255, 230, 179); margin: 20px; padding: 20px; font-size: 20px;">\n <p style="font-weight: bold; font-size: 30px;">Your Docusaurus site did not load properly.</p>\n <p>A very common reason is a wrong site <a href="https://docusaurus.io/docs/docusaurus.config.js/#baseurl" style="font-weight: bold;">baseUrl configuration</a>.</p>\n <p>Current configured baseUrl = <span style="font-weight: bold; color: red;">/</span> (default value)</p>\n <p>We suggest trying baseUrl = <span id="docusaurus-base-url-issue-banner-suggestion-container" style="font-weight: bold; color: green;"></span></p>\n</div>\n';var e=document.getElementById("docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,r="/"===s.substr(-1)?s:s+"/";e.innerHTML=r}}window.__DOCUSAURUS_INSERT_BASEURL_BANNER=!0,document.addEventListener("DOMContentLoaded",maybeInsertBanner)</script><link rel="stylesheet" href="/assets/css/styles.0030965e.css"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Pistache Blog Atom Feed"><title data-react-helmet="true">Pistache</title><meta data-react-helmet="true" property="og:title" content="Pistache"><meta data-react-helmet="true" name="description" content="Description will go into a meta tag in &lt;head /&gt;"><meta data-react-helmet="true" property="og:description" content="Description will go into a meta tag in &lt;head /&gt;"><meta data-react-helmet="true" property="og:url" content="https://pistache.io/"><meta data-react-helmet="true" name="docusaurus_locale" content="en"><meta data-react-helmet="true" name="docusaurus_tag" content="default"><link data-react-helmet="true" rel="shortcut icon" href="/img/logo.png"><link data-react-helmet="true" rel="canonical" href="https://pistache.io/"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/" hreflang="en"><link data-react-helmet="true" rel="alternate" href="https://pistache.io/" hreflang="x-default"><script data-react-helmet="true">function maybeInsertBanner(){window.__DOCUSAURUS_INSERT_BASEURL_BANNER&&insertBanner()}function insertBanner(){var n=document.getElementById("docusaurus-base-url-issue-banner-container");if(n){n.innerHTML='\n<div id="docusaurus-base-url-issue-banner" style="border: thick solid red; background-color: rgb(255, 230, 179); margin: 20px; padding: 20px; font-size: 20px;">\n <p style="font-weight: bold; font-size: 30px;">Your Docusaurus site did not load properly.</p>\n <p>A very common reason is a wrong site <a href="https://docusaurus.io/docs/docusaurus.config.js/#baseurl" style="font-weight: bold;">baseUrl configuration</a>.</p>\n <p>Current configured baseUrl = <span style="font-weight: bold; color: red;">/</span> (default value)</p>\n <p>We suggest trying baseUrl = <span id="docusaurus-base-url-issue-banner-suggestion-container" style="font-weight: bold; color: green;"></span></p>\n</div>\n';var e=document.getElementById("docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,r="/"===s.substr(-1)?s:s+"/";e.innerHTML=r}}window.__DOCUSAURUS_INSERT_BASEURL_BANNER=!0,document.addEventListener("DOMContentLoaded",maybeInsertBanner)</script><link rel="stylesheet" href="/assets/css/styles.0030965e.css">
<link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script"> <link rel="preload" href="/assets/js/runtime~main.da882a54.js" as="script">
<link rel="preload" href="/assets/js/main.d03872b2.js" as="script"> <link rel="preload" href="/assets/js/main.deb2d7f4.js" as="script">
</head> </head>
<body> <body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus"> <script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div id="docusaurus-base-url-issue-banner-container"></div><div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a class="navbar__item navbar__link" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><header class="hero hero--primary heroBanner_3P7f"><div class="container"><h1 class="hero__title">Pistache</h1><p class="hero__subtitle">An elegant C++ REST framework.</p><div class="buttons_1r9m"><a class="button button--outline button--secondary button--lg" href="/docs/">Get Started</a></div></div></header><main><section class="features_3azU"><div class="container"><div class="row"><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_futuristic_interface.svg" alt="Modern API"></div><h3>Modern API</h3><p>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</p></div><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_accept_request.svg" alt="What&#x27;s in the box"></div><h3>What&#x27;s in the box</h3><p></p><ul><li>A multi-threaded HTTP server to build your APIs</li><li>An asynchronous HTTP client to request APIs</li><li>An HTTP router to dispatch requests to C++ functions</li><li>A REST description DSL to easily define your APIs</li><li>Type-safe headers and MIME types implementation</li></ul><p></p></div><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_version_control.svg" alt="Use it"></div><h3>Use it</h3><p></p><ul><li>Clone it on <a href="https://github.com/pistacheio/pistache">GitHub</a></li><li>Start with the <a href="docs/">quickstart</a></li><li>Read the full user&#x27;s <a href="docs/http-handler">guide</a></li><li>Have issues with it? Fill an <a href="https://github.com/pistacheio/pistache/issues">issue</a></li></ul><p></p></div></div></div></section></main></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div> <div id="docusaurus-base-url-issue-banner-container"></div><div><a href="#main" class="skipToContent_1oUP">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle" type="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a><a class="navbar__item navbar__link" href="/docs/">Docs</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="react-toggle displayOnlyInLargeViewport_GrZ2 react-toggle--disabled" role="button" tabindex="-1"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_71bT">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_71bT">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" class="react-toggle-screenreader-only" aria-label="Switch between dark and light mode"></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--light_3UqQ navbar__logo"><img src="/img/logo.png" alt="Pistache logo" class="themedImage_1VuW themedImage--dark_hz6m navbar__logo"><strong class="navbar__title">Pistache</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/">Docs</a></li><li class="menu__list-item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="menu__link header-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><header class="hero hero--primary heroBanner_3P7f"><div class="container"><h1 class="hero__title">Pistache</h1><p class="hero__subtitle">An elegant C++ REST framework.</p><div class="buttons_1r9m"><a class="button button--outline button--secondary button--lg" href="/docs/">Get Started</a></div></div></header><main><section class="features_3azU"><div class="container"><div class="row"><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_futuristic_interface.svg" alt="Modern API"></div><h3>Modern API</h3><p>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</p></div><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_accept_request.svg" alt="What&#x27;s in the box"></div><h3>What&#x27;s in the box</h3><p></p><ul><li>A multi-threaded HTTP server to build your APIs</li><li>An asynchronous HTTP client to request APIs</li><li>An HTTP router to dispatch requests to C++ functions</li><li>A REST description DSL to easily define your APIs</li><li>Type-safe headers and MIME types implementation</li></ul><p></p></div><div class="col col--4"><div class="text--center"><img class="featureImage_ZtzX" src="/img/undraw_version_control.svg" alt="Use it"></div><h3>Use it</h3><p></p><ul><li>Clone it on <a href="https://github.com/pistacheio/pistache">GitHub</a></li><li>Start with the <a href="docs/">quickstart</a></li><li>Read the full user&#x27;s <a href="docs/http-handler">guide</a></li><li>Have issues with it? Fill an <a href="https://github.com/pistacheio/pistache/issues">issue</a></li></ul><p></p></div></div></div></section></main></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/">Quickstart</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/http-handler/">User guide</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow</a></li><li class="footer__item"><a href="irc://chat.freenode.net" target="_blank" rel="noopener noreferrer" class="footer__link-item">#pistache on Freenode</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://github.com/pistacheio/pistache" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Pistache, 2015 - 2021</div></div></div></footer></div>
<script src="/assets/js/runtime~main.da882a54.js"></script> <script src="/assets/js/runtime~main.da882a54.js"></script>
<script src="/assets/js/main.d03872b2.js"></script> <script src="/assets/js/main.deb2d7f4.js"></script>
</body> </body>
</html> </html>
\ 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