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. themes : ['Default']
  8. ---
  9. <script src="/javascript/library/sinon.js"></script>
  10. <script src="/javascript/api.js"></script>
  11. <%- @partial('header', { tabs: 'behavior' }) %>
  12. <div class="main container">
  13. <div class="ui active tab" data-tab="overview">
  14. <div class="ui raised segment">
  15. <div class="ui two column stackable grid">
  16. <div class="row">
  17. <div class="sixteen wide column">
  18. <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>
  19. </div>
  20. </div>
  21. <div class="row">
  22. <div class="column">
  23. <div class="content">
  24. <div class="ui dividing header"><i class="green check icon"></i>Tie API Events to UI</div>
  25. <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>
  26. </div>
  27. </div>
  28. <div class="column">
  29. <div class="content">
  30. <div class="ui dividing header"><i class="green check icon"></i>Interact with actions not memorize URLs</div>
  31. <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>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="row">
  36. <div class="column">
  37. <div class="content">
  38. <div class="ui dividing header"><i class="green check icon"></i>URL Templating built In</div>
  39. <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>
  40. </div>
  41. </div>
  42. <div class="column">
  43. <div class="content">
  44. <div class="ui dividing header"><i class="green check icon"></i>Server Traces For Humans</div>
  45. <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>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="ui tab" data-tab="usage">
  53. <div class="fixed column">
  54. <div class="content">
  55. <h2 class="ui header">Demo</h2>
  56. <div class="ui items">
  57. <div class="item">
  58. <div class="image">
  59. <img src="/images/demo/highres3.jpg">
  60. </div>
  61. <div class="content">
  62. <div class="ui fluid adopt toggle button" data-id="5209">
  63. <i class="checkmark icon"></i>
  64. <span class="text">Adopt</span>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="examples">
  72. <h3 class="ui header">1. Define Your API</h3>
  73. <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>
  74. <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>
  75. <p>For the sake of this example we will use Github's public API as an example</p>
  76. <div class="evaluated code">
  77. /* "Config.js" - Define API endpoints once globally */
  78. $.fn.api.settings.api = {
  79. 'follow user' : '/api/follow/{$id}',
  80. 'user info' : '/api/user/{$id}'
  81. };
  82. </div>
  83. <div class="ignored code" data-type="html">
  84. <!-- Include on any page using API !-->
  85. <script src="/config.js"></script>
  86. </div>
  87. <h3 class="ui header">2. Attach an API event to an element</h3>
  88. <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>
  89. <div class="evaluated code">
  90. $('.adopt.button')
  91. .api({
  92. action: 'follow user'
  93. })
  94. ;
  95. </div>
  96. <h3 class="ui header">2. Specify state changes to text or appearance (optional)</h3>
  97. <p>API couples well with <a href="#">ui state</a>, a component used for managing text state and class names of elements.</p>
  98. <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>
  99. <div class="evaluated code">
  100. $('.adopt.button')
  101. .state({
  102. text: {
  103. inactive : 'Adopt',
  104. active : 'Adopted',
  105. deactivate : 'Undo',
  106. flash : 'Success'
  107. }
  108. })
  109. ;
  110. </div>
  111. <h3 class="ui header">4. Make sure metadata is set for an element before event occurs</h3>
  112. <p>When an API action occurs, templated url data is replaced with data you specify to be sent to the server.</p>
  113. <div class="code" data-type="html">
  114. <div class="ui adopt button" data-id="5209"></div>
  115. </div>
  116. <div class="ui horizontal divider">Or</div>
  117. <p>Alternatively you can modify the data before sending to server</p>
  118. <div class="code">
  119. $('.adopt.button')
  120. .api('setting', 'beforeSend', function(settings) {
  121. settings.urlData.id = 5209;
  122. return settings;
  123. })
  124. ;
  125. </div>
  126. </div>
  127. </div>
  128. <div class="ui tab" data-tab="examples">
  129. </div>
  130. <div class="ui tab" data-tab="settings">
  131. </div>
  132. </div>