PageRenderTime 31ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/jumpstart/app/views/jumpstart/docs/api.html.erb

https://github.com/jlneto/myraces
Ruby HTML | 44 lines | 29 code | 11 blank | 4 comment | 6 complexity | 2ed3f949a06eaf35ad3b977ccaeab924 MD5 | raw file
  1. <% content_for :section_title, "API" %>
  2. <div class="mb-20">
  3. <div class="mb-10">
  4. <p class="mb-4 text-xl text-gray-700 leading-normal">Jumpstart Pro can provide API access to your application with API tokens and authentication already handled for you.</p>
  5. <style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://www.youtube.com/embed//QTCuTL470Qc' frameborder='0' allowfullscreen></iframe></div>
  6. <h2 class="pb-3 mt-6 mb-6 border-b border-gray-400">API Tokens</h2>
  7. <p class="mb-4">Every user in Jumpstart Pro can have multiple API tokens. They can create and revoke tokens on API section of their user settings.</p>
  8. <p class="mb-4">Tokens keep track of the time they were last used so users can verify their integrations are working correctly and keep an eye on them.</p>
  9. <h2 class="pb-3 mb-6 border-b border-gray-400">Authentication</h2>
  10. <p class="mb-4">Authentication with the Jumpstart Pro API is as simple as passing in the <code>Authorization</code> header. We provide an example of this header on the API token page to make it easy for users to implement</p>
  11. <p class="mb-4">An example Authorization header would look like the following:</p>
  12. <pre><code>GET /api/v1/me.json
  13. Authorization: Bearer exampletoken</code></pre>
  14. <p class="mb-4">If you'd like to authenticate users through the API using their email and password to retrieve an API token, you can make a POST request to the auth endpoint with the user's email and password. This is handy for authenticating from a mobile app, etc.</p>
  15. <pre><code>POST /api/v1/auth.json
  16. Params: { email: "steve@apple.com", password: "hunter2" }</code></pre>
  17. <p>This will return a JSON response with a token you can use to access the API.</p>
  18. <pre><code>{ token: "abcd1234" }</code></pre>
  19. <h2 class="pb-3 mb-6 border-b border-gray-400">Controllers & Routes</h2>
  20. <p class="mb-4">API controllers are defined in <code>app/controllers/api/v1/</code>. We provide a <code>/api/v1/me.json</code> and <code>/api/v1/accounts.json</code> endpoint out of the box. You can use these controllers as examples to base your API endpoints off of.</p>
  21. <p class="mb-4">API controllers should inherit from <code>Api::BaseController</code> instead of <code>ApplicationController</code>. This enables API authentication. To skip authentication on an endpoint, add <code>skip_before_action :authenticate_api_token!</code> to your actions.</p>
  22. <p class="mb-4">Authentication works with Devise so you can access <code>current_user</code> just like normal.</p>
  23. <p class="mb-4">Since APIs don't have sessions, there is no <code>current_account</code> equivalent like in the main app. You can use nested resources in the API to scope things under accounts if you want to separate them. For example: <code>/api/v1/accounts/2/projects/4.json</code>.</p>
  24. <h2 class="pb-3 mb-6 border-b border-gray-400">JSON Responses</h2>
  25. <p class="mb-4">API controllers are configured to return JSON by default.</p>
  26. <p class="mb-4">We use JBuilder by default to provide simple JSON templates that most users are already familiar with. To improve JBuilder performance, we have added the <a href="">OJ gem</a> for enhanced JSON performance.</p>
  27. <p class="mb-4">We also recommend checking out the fast_jsonapi gem from Netflix if you'd like to use an alternative.</p>
  28. <!--
  29. <h2 class="pb-3 mb-6 border-b border-gray-400">Adding Resources</h2>
  30. <p class="mb-4"></p>
  31. -->
  32. </div>
  33. </div>