Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Blasting off with the GitHub API

Jamie Strusz
September 13, 2016

Blasting off with the GitHub API

Jamie Strusz

September 13, 2016
Tweet

More Decks by Jamie Strusz

Other Decks in Technology

Transcript

  1. How people build software ! " Blasting off with the

    GitHub API Get a boost with this guided tour of the GitHub API.
  2. How people build software ! Jamie Strusz Services Engineer @

    GitHub Likes art; travels in a vanagon with dog and boyfriend ! allthedoll 2 !
  3. How people build software ! Steve Winton Solutions Engineer @

    GitHub British; resembles Detective Inspector Greg Lestrade on Sherlock ! swinton 4 !
  4. How people build software ! The agenda 6 $ %

    ♥ ! LAUNCH Why even API? ORBIT How to API. FLIGHT Yay, GitHub API!
  5. How people build software ! Lesson 0 8 ! •

    What is an API? • Why even API? • Why use the GitHub API? • Introduction to the GitHub API
  6. How people build software ! What is an API? 9

    ! Source: memegenerator.net
  7. How people build software ! Why even API? 13 !

    Source: johnthetoyshopguy.files.wordpress.com
  8. How people build software ! Examples of what the GitHub

    API can be used for… 16 ! Source: octodex.github.com
  9. How people build software ! The GitHub API is a

    Hypermedia API 19 ! Source: gifs.joelglovier.com
  10. How people build software ! The GitHub API is currently

    at /v3 21 ! Source: memegenerator.net
  11. How people build software ! Lesson 1 23 ! •

    Making Requests • Interacting with the API
  12. How people build software ! Let’s dive in! 24 !

    Source: octodex.github.com and allthedoll
  13. How people build software ! Note that /user returns an

    Unauthorized status… 25 ! Source: giphy.com and allthedoll
  14. How people build software ! Lesson 2 26 ! •

    Diving a little deeper • More on that command line, though • Some example requests with cURL
  15. How people build software ! Example requests 28 ! •

    curl https://api.github.com/zen • curl -i https://api.github.com/users/octocat • Note some interesting headers here: • X-RateLimit-Limit • X-RateLimit-Remaining
  16. How people build software ! Cool tools 29 ! •

    HTTPie • A user-friendly replacement for curl • https://github.com/jkbrzt/httpie • jq • Amazingly useful tool for processing JSON from the command-line • https://stedolan.github.io/jq/ • Example: • curl 'https://api.github.com/repos/atom/atom/commits?per_page=5' | jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
  17. How people build software ! Lesson 3 31 ! •

    Rate limits • Bummer. • Authentication • Sweet.
  18. How people build software ! Rate limits: a fact of

    life. 32 ! Source: mememaker.net
  19. How people build software ! Lesson 4 34 ! •

    Authentication • Basic • OAuth • Personal access tokens
  20. How people build software ! Authenticating 36 ! • Basic

    auth • curl -u "swinton:$GITHUB_PASS" -i https://api.github.com/user • 2FA • curl -u "swinton:$GITHUB_PASS" -H "X-GitHub-OTP: $GITHUB_OTP" -i https:// api.github.com/user • This is painful, and sharing passwords with others (including applications) is an anti-pattern.
  21. How people build software ! OAuth Web Flow 37 !

    • TLDR: OAuth gives third-parties access to your stuff without you sharing your password • It uses access keys, which limits the scope of what third parties can do • Different access keys can be issued per third-party to track who did what with your stuff
  22. How people build software ! Personal access tokens are like

    hotel keys 38 ! Source: memegenerator.net
  23. How people build software ! Personal access tokens 39 !

    • TLDR: Personal access tokens give third-parties access to your stuff without you sharing your password • Tokens act like you when they’re used, so keep them secret • Different access keys can be issued per third-party to track who did what with your stuff
  24. How people build software ! Let’s generate an access token

    super quick 40 ! Source: allthedoll • https://github.com/settings/tokens • Give it a good Token description
  25. How people build software ! Let’s use it! 42 !

    • Copy your access token (treat it like a password), and save it in an environment variable • GITHUB_ACCESS_TOKEN2=$( pbpaste ) • Hit up the API! • curl -i -H "Authorization: token $GITHUB_ACCESS_TOKEN2" https:// api.github.com/user
  26. How people build software ! Lesson 5 45 ! •

    Oktokit! • https://github.com/octokit/octokit.rb
  27. How people build software ! Lesson 6 47 ! •

    Get to know Octokit a little better • Events • Pagination • Everything you did today on GitHub
  28. How people build software ! Lesson 7 49 ! •

    What is a webhook and why is it not an API? • Webhooks and GitHub • Configure a webhook to call your web app • Test it by changing something on GitHub
  29. How people build software ! What is a webhook and

    why is it not an API? 50 ! Source: quickmeme.com
  30. How people build software ! Lesson 8 54 ! •

    Other resources exposed by the GitHub API
  31. How people build software ! Look at all the possibilities

    I have! 55 ! Source: technologytell.com
  32. How people build software ! Lesson 9 56 ! •

    Other useful tools for API development • httpbin.org - https://httpbin.org/ • HTTP request and response service • ngrok - https://ngrok.com/ • Secure tunnels to localhost • Charles - https://www.charlesproxy.com/ • HTTP proxy / HTTP monitor / Reverse proxy to view all HTTP and SSL/HTTPS traffic • Paw - https://paw.cloud/ • A full-featured HTTP client that lets you test the APIs you build or consume • Postman - https://www.getpostman.com/ • Build APIs, faster
  33. How people build software ! Lesson 10 57 ! •

    Try different things and explore the possibilities!
  34. How people build software ! You can find Steve on

    BBC’s Sherlock, on GitHub, and the Twitterverse: stevewinton ! swinton Our information: 59 ! You can find Jamie in her van, on GitHub, and alltheinternet: @allthedoll ! Jamie ! Steve