diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-27 10:27:51 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-05-27 10:27:51 -0700 |
commit | 78de7ed98abff93fe5fef94907bcfa4f76dcef07 (patch) | |
tree | f58578554dc829a046762e588d8b190af89dd992 /docs/build/References/Overview | |
parent | 38aa0ebb1df97ff185d84da2d3c2f9a11888729b (diff) |
adding docs to repo
Diffstat (limited to 'docs/build/References/Overview')
-rw-r--r-- | docs/build/References/Overview/index.html | 1163 |
1 files changed, 1163 insertions, 0 deletions
diff --git a/docs/build/References/Overview/index.html b/docs/build/References/Overview/index.html new file mode 100644 index 0000000..6766130 --- /dev/null +++ b/docs/build/References/Overview/index.html @@ -0,0 +1,1163 @@ + +<!DOCTYPE html> +<html lang="en" class="no-js"> + <head> + + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width,initial-scale=1"> + + + + + <link rel="shortcut icon" href="../../assets/images/favicon.png"> + + <meta name="generator" content="mkdocs-0.16.3, mkdocs-material-1.6.1"> + + + + <title>References in Ponzu</title> + + + + <script src="../../assets/javascripts/modernizr-56ade86843.js"></script> + + + <link rel="stylesheet" href="../../assets/stylesheets/application-4d0d3f2fbf.css"> + + <link rel="stylesheet" href="../../assets/stylesheets/application-f78e5cb881.palette.css"> + + + + + + + + <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono"> + <style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style> + + <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> + + + + </head> + + + + + <body data-md-color-primary="grey" data-md-color-accent="light-blue"> + + <svg class="md-svg"> + <defs> + + + <svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg> + + </defs> + </svg> + <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="drawer"> + <input class="md-toggle" data-md-toggle="search" type="checkbox" id="search"> + <label class="md-overlay" data-md-component="overlay" for="drawer"></label> + + <header class="md-header" data-md-component="header"> + <nav class="md-header-nav md-grid"> + <div class="md-flex"> + <div class="md-flex__cell md-flex__cell--shrink"> + + <a href="../.." title="Ponzu" class="md-logo md-header-nav__button"> + <img src="../../images/logo.png" width="24" height="24"> + </a> + + </div> + <div class="md-flex__cell md-flex__cell--shrink"> + <label class="md-icon md-icon--menu md-header-nav__button" for="drawer"></label> + </div> + <div class="md-flex__cell md-flex__cell--stretch"> + <span class="md-flex__ellipsis md-header-nav__title"> + + + + <span class="md-header-nav__parent"> + References + </span> + + + Overview + + </span> + </div> + <div class="md-flex__cell md-flex__cell--shrink"> + + <label class="md-icon md-icon--search md-header-nav__button" for="search"></label> + +<div class="md-search" data-md-component="search"> + <label class="md-search__overlay" for="search"></label> + <div class="md-search__inner"> + <form class="md-search__form" name="search"> + <input type="text" class="md-search__input" name="query" required placeholder="Search" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query"> + <label class="md-icon md-search__icon" for="search"></label> + <button type="reset" class="md-icon md-search__icon" data-md-component="reset">close</button> + </form> + <div class="md-search__output"> + <div class="md-search__scrollwrap" data-md-scrollfix> + <div class="md-search-result" data-md-component="result"> + <div class="md-search-result__meta" data-md-lang-result-none="No matching documents" data-md-lang-result-one="1 matching document" data-md-lang-result-other="# matching documents"> + Type to start searching + </div> + <ol class="md-search-result__list"></ol> + </div> + </div> + </div> + </div> +</div> + + </div> + <div class="md-flex__cell md-flex__cell--shrink"> + <div class="md-header-nav__source"> + + + + + + + + <a href="https://github.com/ponzu-cms/ponzu" title="Go to repository" class="md-source" data-md-source="github"> + + <div class="md-source__icon"> + <svg viewBox="0 0 24 24" width="24" height="24"> + <use xlink:href="#github" width="24" height="24"></use> + </svg> + </div> + + <div class="md-source__repository"> + ponzu-cms/ponzu + </div> + </a> + + + </div> + </div> + </div> + </nav> +</header> + + <div class="md-container"> + + + <main class="md-main"> + <div class="md-main__inner md-grid" data-md-component="container"> + + + <div class="md-sidebar md-sidebar--primary" data-md-component="navigation"> + <div class="md-sidebar__scrollwrap"> + <div class="md-sidebar__inner"> + <nav class="md-nav md-nav--primary" data-md-level="0"> + <label class="md-nav__title md-nav__title--site" for="drawer"> + + <i class="md-logo md-nav__button"> + <img src="../../images/logo.png"> + </i> + + Ponzu + </label> + + <div class="md-nav__source"> + + + + + + + <a href="https://github.com/ponzu-cms/ponzu" title="Go to repository" class="md-source" data-md-source="github"> + + <div class="md-source__icon"> + <svg viewBox="0 0 24 24" width="24" height="24"> + <use xlink:href="#github" width="24" height="24"></use> + </svg> + </div> + + <div class="md-source__repository"> + ponzu-cms/ponzu + </div> + </a> + + </div> + + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + <li class="md-nav__item"> + <a href="../.." title="Home" class="md-nav__link"> + Home + </a> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-2" type="checkbox" id="nav-2"> + + <label class="md-nav__link" for="nav-2"> + CLI + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-2"> + CLI + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../CLI/General-Usage/" title="General Usage" class="md-nav__link"> + General Usage + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../CLI/Generating-References/" title="Generating References" class="md-nav__link"> + Generating References + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-3" type="checkbox" id="nav-3"> + + <label class="md-nav__link" for="nav-3"> + Content + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-3"> + Content + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Content/An-Overview/" title="An Overview" class="md-nav__link"> + An Overview + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Content/Extending-Content/" title="Extending Content" class="md-nav__link"> + Extending Content + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-4" type="checkbox" id="nav-4"> + + <label class="md-nav__link" for="nav-4"> + Form Fields + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-4"> + Form Fields + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Form-Fields/HTML-Inputs/" title="HTML Inputs" class="md-nav__link"> + HTML Inputs + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5"> + + <label class="md-nav__link" for="nav-5"> + HTTP APIs + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-5"> + HTTP APIs + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../HTTP-APIs/Content/" title="Content" class="md-nav__link"> + Content + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../HTTP-APIs/File-Metadata/" title="File Metadata" class="md-nav__link"> + File Metadata + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../HTTP-APIs/Search/" title="Search" class="md-nav__link"> + Search + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6"> + + <label class="md-nav__link" for="nav-6"> + Interfaces + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-6"> + Interfaces + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Interfaces/API/" title="API" class="md-nav__link"> + API + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Interfaces/Editor/" title="Editor" class="md-nav__link"> + Editor + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Interfaces/Format/" title="Format" class="md-nav__link"> + Format + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Interfaces/Item/" title="Item" class="md-nav__link"> + Item + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Interfaces/Search/" title="Search" class="md-nav__link"> + Search + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7"> + + <label class="md-nav__link" for="nav-7"> + Ponzu Addons + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-7"> + Ponzu Addons + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Ponzu-Addons/Creating-Addons/" title="Creating Addons" class="md-nav__link"> + Creating Addons + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../Ponzu-Addons/Using-Addons/" title="Using Addons" class="md-nav__link"> + Using Addons + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8"> + + <label class="md-nav__link" for="nav-8"> + Quickstart + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-8"> + Quickstart + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Quickstart/Overview/" title="Overview" class="md-nav__link"> + Overview + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + + + <li class="md-nav__item md-nav__item--active md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-9" type="checkbox" id="nav-9" checked> + + <label class="md-nav__link" for="nav-9"> + References + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-9"> + References + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + + + <li class="md-nav__item md-nav__item--active"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="toc"> + + + <label class="md-nav__link md-nav__link--active" for="toc"> + Overview + </label> + + <a href="./" title="Overview" class="md-nav__link md-nav__link--active"> + Overview + </a> + + +<nav class="md-nav md-nav--secondary"> + + + + <label class="md-nav__title" for="toc">Table of contents</label> + <ul class="md-nav__list" data-md-scrollfix> + + <li class="md-nav__item"> + <a href="#create-your-content-types" title="Create Your Content Types" class="md-nav__link"> + Create Your Content Types + </a> + +</li> + + <li class="md-nav__item"> + <a href="#designed-for-http2" title="Designed For HTTP/2" class="md-nav__link"> + Designed For HTTP/2 + </a> + + <nav class="md-nav"> + <ul class="md-nav__list"> + + <li class="md-nav__item"> + <a href="#requestresponse-multiplexing" title="Request/Response Multiplexing" class="md-nav__link"> + Request/Response Multiplexing + </a> + +</li> + + <li class="md-nav__item"> + <a href="#server-push" title="Server Push" class="md-nav__link"> + Server Push + </a> + + <nav class="md-nav"> + <ul class="md-nav__list"> + + <li class="md-nav__item"> + <a href="#example" title="Example" class="md-nav__link"> + Example + </a> + +</li> + + </ul> + </nav> + +</li> + + </ul> + </nav> + +</li> + + <li class="md-nav__item"> + <a href="#other-considerations" title="Other Considerations" class="md-nav__link"> + Other Considerations + </a> + +</li> + + + + </ul> + +</nav> + + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-10" type="checkbox" id="nav-10"> + + <label class="md-nav__link" for="nav-10"> + Running Backups + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-10"> + Running Backups + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../Running-Backups/Backups/" title="Backups" class="md-nav__link"> + Backups + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-11" type="checkbox" id="nav-11"> + + <label class="md-nav__link" for="nav-11"> + System Configuration + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-11"> + System Configuration + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../System-Configuration/Settings/" title="Settings" class="md-nav__link"> + Settings + </a> + </li> + + + </ul> + </nav> + </li> + + + + + + + + <li class="md-nav__item md-nav__item--nested"> + + <input class="md-toggle md-nav__toggle" data-md-toggle="nav-12" type="checkbox" id="nav-12"> + + <label class="md-nav__link" for="nav-12"> + System Deployment + </label> + <nav class="md-nav" data-md-component="collapsible" data-md-level="1"> + <label class="md-nav__title" for="nav-12"> + System Deployment + </label> + <ul class="md-nav__list" data-md-scrollfix> + + + + + + + + <li class="md-nav__item"> + <a href="../../System-Deployment/Docker/" title="Docker" class="md-nav__link"> + Docker + </a> + </li> + + + + + + + + <li class="md-nav__item"> + <a href="../../System-Deployment/SysV-Style/" title="SysV Style" class="md-nav__link"> + SysV Style + </a> + </li> + + + </ul> + </nav> + </li> + + + </ul> +</nav> + </div> + </div> + </div> + + + <div class="md-sidebar md-sidebar--secondary" data-md-component="toc"> + <div class="md-sidebar__scrollwrap"> + <div class="md-sidebar__inner"> + +<nav class="md-nav md-nav--secondary"> + + + + <label class="md-nav__title" for="toc">Table of contents</label> + <ul class="md-nav__list" data-md-scrollfix> + + <li class="md-nav__item"> + <a href="#create-your-content-types" title="Create Your Content Types" class="md-nav__link"> + Create Your Content Types + </a> + +</li> + + <li class="md-nav__item"> + <a href="#designed-for-http2" title="Designed For HTTP/2" class="md-nav__link"> + Designed For HTTP/2 + </a> + + <nav class="md-nav"> + <ul class="md-nav__list"> + + <li class="md-nav__item"> + <a href="#requestresponse-multiplexing" title="Request/Response Multiplexing" class="md-nav__link"> + Request/Response Multiplexing + </a> + +</li> + + <li class="md-nav__item"> + <a href="#server-push" title="Server Push" class="md-nav__link"> + Server Push + </a> + + <nav class="md-nav"> + <ul class="md-nav__list"> + + <li class="md-nav__item"> + <a href="#example" title="Example" class="md-nav__link"> + Example + </a> + +</li> + + </ul> + </nav> + +</li> + + </ul> + </nav> + +</li> + + <li class="md-nav__item"> + <a href="#other-considerations" title="Other Considerations" class="md-nav__link"> + Other Considerations + </a> + +</li> + + + + </ul> + +</nav> + </div> + </div> + </div> + + + <div class="md-content"> + <article class="md-content__inner md-typeset"> + + + + <h1>Overview</h1> + + <p>References in Ponzu allow you to create relationships between your Content types. +Ponzu uses an embedded database, rather than a more traditional relational database +with SQL support. This may seem unnatural since there is no native concept of +"foreign keys" or "joins" like you may be used to. Instead, Ponzu wires up your +data using references, which are simply URL paths, like <code>/api/content?type=Post&id=1</code></p> +<p>A foreign key as a URL path?! Am I crazy? No! For the purpose Ponzu serves, +this structure works quite well, especially given its creation was specifically +tuned for HTTP/2 features such as "Request/Response Multiplexing" and "Server Push." </p> +<p>There is a deeper dive into the HTTP/2 concepts <a href="../../References/Overview/#designed-for-http2">below</a>, but first we'll walk through +a quick tutorial on Ponzu's references. </p> +<p>To generate references from the CLI, please <a href="../../CLI/Generating-References">read through the documentation</a>. +The example below assumes you understand the syntax. </p> +<hr /> +<h3 id="create-your-content-types">Create Your Content Types<a class="headerlink" href="#create-your-content-types" title="Permanent link">¶</a></h3> +<p>Here we are creating two Content types, <code>Author</code> and <code>Book</code>. A <code>Book</code> will keep +a reference to an <code>Author</code> in the sense that an author wrote the book.</p> +<div class="codehilite"><pre><span></span>$ ponzu gen c author name:string photo:string:file bio:string:textarea +$ ponzu gen c book title:string author:@author,name pages:int year:int +</pre></div> + + +<p>The structs generated for each look like:</p> +<p><code>content/author.go</code></p> +<div class="codehilite"><pre><span></span><span class="kd">type</span> <span class="nx">Author</span> <span class="kd">struct</span> <span class="p">{</span> + <span class="nx">item</span><span class="p">.</span><span class="nx">Item</span> + + <span class="nx">Name</span> <span class="kt">string</span> <span class="s">`json:"name"`</span> + <span class="nx">Photo</span> <span class="kt">string</span> <span class="s">`json:"photo"`</span> + <span class="nx">Bio</span> <span class="kt">string</span> <span class="s">`json:"bio"`</span> +<span class="p">}</span> +</pre></div> + + +<p><code>content/book.go</code></p> +<div class="codehilite"><pre><span></span><span class="kd">type</span> <span class="nx">Book</span> <span class="kd">struct</span> <span class="p">{</span> + <span class="nx">item</span><span class="p">.</span><span class="nx">Item</span> + + <span class="nx">Title</span> <span class="kt">string</span> <span class="s">`json:"title"`</span> + <span class="nx">Author</span> <span class="kt">string</span> <span class="s">`json:"author"`</span> + <span class="nx">Pages</span> <span class="kt">int</span> <span class="s">`json:"pages"`</span> + <span class="nx">Year</span> <span class="kt">int</span> <span class="s">`json:"year"`</span> +<span class="p">}</span> +</pre></div> + + +<p>Notice how the <code>Author</code> field within the <code>Book</code> struct is a <code>string</code> type, not +an <code>Author</code> type. This is because the <code>Author</code> is stored as a <code>string</code> in our +database, as a reference to the <code>Author</code>, instead of embedding the <code>Author</code> data +inside the <code>Book</code>. </p> +<p>Some example JSON data for the two structs looks like:</p> +<p><kbd>GET</kbd> <code>/api/content?type=Author&id=1</code> (<code>Author</code>)</p> +<div class="codehilite"><pre><span></span><span class="p">{</span> + <span class="nt">"data"</span><span class="p">:</span> <span class="p">[</span> + <span class="p">{</span> + <span class="nt">"uuid"</span><span class="p">:</span> <span class="s2">"024a5797-e064-4ee0-abe3-415cb6d3ed18"</span><span class="p">,</span> + <span class="nt">"id"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> + <span class="nt">"slug"</span><span class="p">:</span> <span class="s2">"item-id-024a5797-e064-4ee0-abe3-415cb6d3ed18"</span><span class="p">,</span> + <span class="nt">"timestamp"</span><span class="p">:</span> <span class="mi">1493926453826</span><span class="p">,</span> + <span class="nt">"updated"</span><span class="p">:</span> <span class="mi">1493926453826</span><span class="p">,</span> + <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Shel Silverstein"</span><span class="p">,</span> + <span class="nt">"photo"</span><span class="p">:</span> <span class="s2">"/api/uploads/2017/05/shel-silverstein.jpg"</span><span class="p">,</span> + <span class="nt">"bio"</span><span class="p">:</span> <span class="s2">"Sheldon Allan Silverstein was an American poet..."</span> + <span class="p">}</span> + <span class="p">]</span> +<span class="p">}</span> +</pre></div> + + +<p><kbd>GET</kbd> <code>/api/content?type=Book&id=1</code> (<code>Book</code>)</p> +<div class="codehilite"><pre><span></span><span class="p">{</span> + <span class="nt">"data"</span><span class="p">:</span> <span class="p">[</span> + <span class="p">{</span> + <span class="nt">"uuid"</span><span class="p">:</span> <span class="s2">"024a5797-e064-4ee0-abe3-415cb6d3ed18"</span><span class="p">,</span> + <span class="nt">"id"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> + <span class="nt">"slug"</span><span class="p">:</span> <span class="s2">"item-id-024a5797-e064-4ee0-abe3-415cb6d3ed18"</span><span class="p">,</span> + <span class="nt">"timestamp"</span><span class="p">:</span> <span class="mi">1493926453826</span><span class="p">,</span> + <span class="nt">"updated"</span><span class="p">:</span> <span class="mi">1493926453826</span><span class="p">,</span> + <span class="nt">"title"</span><span class="p">:</span> <span class="s2">"The Giving Tree"</span><span class="p">,</span> + <span class="nt">"author"</span><span class="p">:</span> <span class="s2">"/api/content?type=Author&id=1"</span><span class="p">,</span> + <span class="nt">"pages"</span><span class="p">:</span> <span class="mi">57</span><span class="p">,</span> + <span class="nt">"year"</span><span class="p">:</span> <span class="mi">1964</span> + <span class="p">}</span> + <span class="p">]</span> +<span class="p">}</span> +</pre></div> + + +<p>As you can see, the <code>Author</code> is a reference as the <code>author</code> field in the JSON +response for a <code>Book</code>. When you're building your client, you need to make a second +request for the <code>Author</code>, to the URL path found in the <code>author</code> field of the <code>Book</code> +response. </p> +<p>For example, in pseudo-code: </p> +<div class="codehilite"><pre><span></span><span class="c1"># Request 1: </span> +<span class="nv">$book</span> <span class="o">=</span> GET /api/content?type<span class="o">=</span>Book<span class="p">&</span><span class="nv">id</span><span class="o">=</span><span class="m">1</span> + +<span class="c1"># Request 2: </span> +<span class="nv">$author</span> <span class="o">=</span> GET <span class="nv">$book</span>.author <span class="c1"># where author = /api/content?type=Author&id=1</span> +</pre></div> + + +<p>Until recently, this would be considered bad practice and would be costly to do +over HTTP. However, with the wide availability of HTTP/2 clients, including all +modern web browsers, mobile devices, and HTTP/2 libraries in practically every +programming language, this pattern is fast and scalable. </p> +<hr /> +<h3 id="designed-for-http2">Designed For HTTP/2<a class="headerlink" href="#designed-for-http2" title="Permanent link">¶</a></h3> +<p>At this point, you've likely noticed that you're still making two independent +HTTP requests to your Ponzu server. Further, if there are multiple references or more +than one item, you'll be making many requests -- <em>how can that be efficient?</em> </p> +<p>There are two main concepts at play: Request/Response Multiplexing and Server Push.</p> +<h4 id="requestresponse-multiplexing">Request/Response Multiplexing<a class="headerlink" href="#requestresponse-multiplexing" title="Permanent link">¶</a></h4> +<p>With HTTP/2, a client and server (peers) transfer data over a single TCP connection, +and can send data back and forth at the same time. No longer does a request need +to wait to be sent until after an expected response is read. This means that HTTP +requests can be sent much faster and at the <em>same time</em> on a single connection. +Where previously, a client would open up several TCP connections, the re-use of a +single connection reduces CPU overhead and makes the server more efficient.</p> +<p>This feature is automatically provided to you when using HTTP/2 - the only +requirement is that you connect via HTTPS and have active TLS certificates, which +you can get for free by running Ponzu with the <code>--https</code> flag and configuring it +with a properly set, active domain name of your own. </p> +<h4 id="server-push">Server Push<a class="headerlink" href="#server-push" title="Permanent link">¶</a></h4> +<p>Another impactful feature of HTTP/2 is "Server Push": the ability to preemptively +send a response from the server to a client without waiting for a request. This +is where Ponzu's reference design really shows it's power. Let's revisit the +example from above:</p> +<div class="codehilite"><pre><span></span><span class="c1"># Request 1: </span> +<span class="nv">$book</span> <span class="o">=</span> GET /api/content?type<span class="o">=</span>Book<span class="p">&</span><span class="nv">id</span><span class="o">=</span><span class="m">1</span> + +<span class="c1"># Request 2: </span> +<span class="nv">$author</span> <span class="o">=</span> GET <span class="nv">$book</span>.author <span class="c1"># where author = /api/content?type=Author&id=1</span> +</pre></div> + + +<p>Instead of waiting for the server to respond with the data for <code>$book.author</code>, +the response data is already in the client's cache before we even make the request! +Now there is no round-trip made to the server and back, and the client reads the +pushed response from cache in fractions of a millisecond. </p> +<p>But, how does the server know which response to push and when? You'll need to +specify which fields of the type you've requested should be pushed. This is done +by implementing the <a href="../../Interfaces/Item#itempushable"><code>item.Pushable</code> interface</a>. +See the example below which demonstrates a complete implementation on the <code>Book</code> +struct, which has a reference to an <code>Author</code>.</p> +<h5 id="example">Example<a class="headerlink" href="#example" title="Permanent link">¶</a></h5> +<p><code>content/book.go</code></p> +<div class="codehilite"><pre><span></span><span class="o">...</span> +<span class="kd">type</span> <span class="nx">Book</span> <span class="kd">struct</span> <span class="p">{</span> + <span class="nx">item</span><span class="p">.</span><span class="nx">Item</span> + + <span class="nx">Title</span> <span class="kt">string</span> <span class="s">`json:"title"`</span> + <span class="nx">Author</span> <span class="kt">string</span> <span class="s">`json:"author"`</span> + <span class="nx">Pages</span> <span class="kt">int</span> <span class="s">`json:"pages"`</span> + <span class="nx">Year</span> <span class="kt">int</span> <span class="s">`json:"year"`</span> +<span class="p">}</span> + + +<span class="kd">func</span> <span class="p">(</span><span class="nx">b</span> <span class="o">*</span><span class="nx">Book</span><span class="p">)</span> <span class="nx">Push</span><span class="p">()</span> <span class="p">[]</span><span class="kt">string</span> <span class="p">{</span> + <span class="k">return</span> <span class="p">[]</span><span class="kt">string</span><span class="p">{</span> + <span class="c1">// the json struct tag is used to tell the server which</span> + <span class="c1">// field(s) it should push - only URL paths originating</span> + <span class="c1">// from your server can be pushed!</span> + <span class="s">"author"</span><span class="p">,</span> + <span class="p">}</span> +<span class="p">}</span> +<span class="o">...</span> +</pre></div> + + +<p>Now, whenever a single <code>Book</code> is requested, the server will preemptively push the +<code>Author</code> referenced by the book. The response for the <code>Author</code> will <em>already be +on the client</em> and will remain there until a request for the referenced <code>Author</code> +has been made.</p> +<div class="admonition note"> +<p class="admonition-title">What else can I Push?</p> +<p>Only fields that are URL paths originating from your server can be pushed. +This means that you could also implement <code>item.Pushable</code> on the <code>Author</code> +type, and return <code>[]string{"photo"}</code> to push the Author's image!</p> +</div> +<hr /> +<h3 id="other-considerations">Other Considerations<a class="headerlink" href="#other-considerations" title="Permanent link">¶</a></h3> +<p>HTTP/2 Server Push is a powerful feature, but it can be abused just like anything +else. To try and help mitigate potential issues, Ponzu has put some "stop-gaps" +in place. Server Push is only activated on <strong>single item</strong> API responses, so you +shouldn't expect to see references or files pushed from the <code>/api/contents</code> endpoint. +An exception to this is the <code>/api/search</code> endpoint, which only the <strong>first</strong> +result is pushed (if applicable) no matter how many items are in the response. </p> +<p>You should take advantage of HTTP/2 in Ponzu and get the most out of the system. +With the automatic HTTPS feature, there is no reason not to and you gain the +additional benefit of encrypting your traffic - which your users will appreciate!</p> + + + + + + + + </article> + </div> + </div> + </main> + + +<footer class="md-footer"> + + <div class="md-footer-nav"> + <nav class="md-footer-nav__inner md-grid"> + + <a href="../../Quickstart/Overview/" title="Overview" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev"> + <div class="md-flex__cell md-flex__cell--shrink"> + <i class="md-icon md-icon--arrow-back md-footer-nav__button"></i> + </div> + <div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title"> + <span class="md-flex__ellipsis"> + <span class="md-footer-nav__direction"> + Previous + </span> + Overview + </span> + </div> + </a> + + + <a href="../../Running-Backups/Backups/" title="Backups" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next"> + <div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title"> + <span class="md-flex__ellipsis"> + <span class="md-footer-nav__direction"> + Next + </span> + Backups + </span> + </div> + <div class="md-flex__cell md-flex__cell--shrink"> + <i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i> + </div> + </a> + + </nav> + </div> + + <div class="md-footer-meta md-typeset"> + <div class="md-footer-meta__inner md-grid"> + <div class="md-footer-copyright"> + + powered by + <a href="http://www.mkdocs.org" title="MkDocs">MkDocs</a> + and + <a href="http://squidfunk.github.io/mkdocs-material/" title="Material for MkDocs"> + Material for MkDocs</a> + </div> + + + <div class="md-footer-social"> + + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> + + <a href="https://github.com/ponzu-cms" class="md-footer-social__link fa fa-github"></a> + + <a href="https://twitter.com/ponzu_cms" class="md-footer-social__link fa fa-twitter"></a> + + </div> + + + </div> + </div> +</footer> + + </div> + + <script src="../../assets/javascripts/application-6b599127bc.js"></script> + <script>app.initialize({url:{base:"../.."}})</script> + + + + + <script>!function(e,t,a,n,o,c,i){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,c=t.createElement(a),i=t.getElementsByTagName(a)[0],c.async=1,c.src=n,i.parentNode.insertBefore(c,i)}(window,document,"script","https://www.google-analytics.com/analytics.js","ga"),ga("create","UA-98609560-1","auto"),ga("set","anonymizeIp",!0),ga("send","pageview");var links=document.getElementsByTagName("a");Array.prototype.map.call(links,function(e){e.host!=document.location.host&&e.addEventListener("click",function(){var t=e.getAttribute("data-md-action")||"follow";ga("send","event","outbound",t,e.href)})});var query=document.forms.search.query;query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})</script> + + + </body> +</html>
\ No newline at end of file |