You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
6.1 KiB

  1. ---
  2. layout : 'default'
  3. css : 'api'
  4. title : 'API'
  5. description : 'API allows UI elements to send events to the server'
  6. type : 'Draft'
  7. ---
  8. <script src="/javascript/library/sinon.js"></script>
  9. <script src="/javascript/api.js"></script>
  10. <%- @partial('header', { tabs: 'behavior' }) %>
  11. <div class="main container">
  12. <div class="ui active tab" data-tab="overview">
  13. <div class="ui raised segment">
  14. <div class="ui two column stackable grid">
  15. <div class="row">
  16. <div class="sixteen wide column">
  17. <p>Semantic API helps attach server events to UI elements. There a few key features which make API more useful then jQuery AJAX or and simpler than MVC patterns.</p>
  18. </div>
  19. </div>
  20. <div class="row">
  21. <div class="column">
  22. <div class="content">
  23. <div class="ui dividing header"><i class="green check icon"></i>Tie API Events to UI</div>
  24. <p>API is built specifically to interact with user interfaces, allowing features like, ui state management, rate throttling, single-request limits, minimum request time, and other features specifically designed to make server loads more human-friendly.</p>
  25. </div>
  26. </div>
  27. <div class="column">
  28. <div class="content">
  29. <div class="ui dividing header"><i class="green check icon"></i>Interact with actions not memorize URLs</div>
  30. <p>Using API helps wrangle in your API endpoints, by managing them together as a whole. Update all your endpoints from a single location. Provide developers access to your API by exporting your API endpoints for others to use.</p>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="row">
  35. <div class="column">
  36. <div class="content">
  37. <div class="ui dividing header"><i class="green check icon"></i>URL Templating built In</div>
  38. <p>API is made for REST. Store your API endpoints with url variables that are replaced at run-time. No need to manually update urls to match data, its bound automatically</p>
  39. </div>
  40. </div>
  41. <div class="column">
  42. <div class="content">
  43. <div class="ui dividing header"><i class="green check icon"></i>Server Traces For Humans</div>
  44. <p>API is built with the same trace and performance tools as other Semantic components allowing you to view english language traces of server requests letting you see where things fail.</p>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="ui tab" data-tab="usage">
  52. <div class="fixed column">
  53. <div class="content">
  54. <h2 class="ui header">Demo</h2>
  55. <div class="ui items">
  56. <div class="item">
  57. <div class="image">
  58. <img src="/images/demo/highres3.jpg">
  59. </div>
  60. <div class="content">
  61. <div class="ui fluid adopt toggle button" data-id="5209">
  62. <i class="checkmark icon"></i>
  63. <span class="text">Adopt</span>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="examples">
  71. <h3 class="ui header">1. Define Your API</h3>
  72. <p><b>API</b> works best when using a named list of endpoints. This means you can maintain all of your website's API endpoints in a single location, without having to update them across the site.</p>
  73. <p>To do this you must include a list of named endpoints before calling <code>$.api</code> on any page. The easiest way to do this is to have it available in a stand-alone configuration file.</p>
  74. <p>For the sake of this example we will use Github's public API as an example</p>
  75. <div class="evaluated code">
  76. /* "Config.js" - Define API endpoints once globally */
  77. $.fn.api.settings.api = {
  78. 'follow user' : '/api/follow/{$id}',
  79. 'user info' : '/api/user/{$id}'
  80. };
  81. </div>
  82. <div class="ignored code" data-type="html">
  83. <!-- Include on any page using API !-->
  84. <script src="/config.js"></script>
  85. </div>
  86. <h3 class="ui header">2. Attach an API event to an element</h3>
  87. <p>Any element can have an API action attached, by default the action will occur on the most relevant event for the type of element. For example a button will use on <code>click</code> or an input <code>oninputchange</code></p>
  88. <div class="evaluated code">
  89. $('.adopt.button')
  90. .api({
  91. action: 'follow user'
  92. })
  93. ;
  94. </div>
  95. <h3 class="ui header">2. Specify state changes to text or appearance (optional)</h3>
  96. <p>API couples well with <a href="#">ui state</a>, a component used for managing text state and class names of elements.</p>
  97. <p>State will automatically apply the class <code>active</code> on API success, and update any text nodes with new values specified. This example updates the text of a follow button to "following" when the API action is successful, after flashing the text success.</p>
  98. <div class="evaluated code">
  99. $('.adopt.button')
  100. .state({
  101. text: {
  102. inactive : 'Adopt',
  103. active : 'Adopted',
  104. deactivate : 'Undo',
  105. flash : 'Success'
  106. }
  107. })
  108. ;
  109. </div>
  110. <h3 class="ui header">4. Make sure metadata is set for an element before event occurs</h3>
  111. <p>When an API action occurs, templated url data is replaced with data you specify to be sent to the server.</p>
  112. <div class="code" data-type="html">
  113. <div class="ui adopt button" data-id="5209"></div>
  114. </div>
  115. <div class="ui horizontal divider">Or</div>
  116. <p>Alternatively you can modify the data before sending to server</p>
  117. <div class="code">
  118. $('.adopt.button')
  119. .api('setting', 'beforeSend', function(settings) {
  120. settings.urlData.id = 5209;
  121. return settings;
  122. })
  123. ;
  124. </div>
  125. </div>
  126. </div>
  127. <div class="ui tab" data-tab="examples">
  128. </div>
  129. <div class="ui tab" data-tab="settings">
  130. </div>
  131. </div>
  132. </body>
  133. </html>