Build a Cross-Platform Web API CLI in 15 minutes with Mruby-CLI

Build a Cross-Platform Web API CLI in 15 minutes with Mruby-CLI

Thanks to web APIs, we can extend any web apps with simple Ruby CLI: listing open pull requests, or tweeting directly from the terminal.

Unfortunately, distributing Ruby CLIs is complicated. So many runtimes to support, so hard to guarantee compatibility of gems on every platforms.

With mruby-cli, you can easily build an API CLI in mruby, a Ruby sibbling, and distribute it for every major platforms.

In this talk, we'll show how quickly you can build and distribute a such CLI with mruby-cli.

GitHub Repository:
- mruby-cli https://github.com/hone/mruby-cli
- mruby-web_api https://travis-ci.org/toch/mruby-web_api
- github_status https://github.com/toch/github_status

Screencasts of the live coding made during the talk https://gfycat.com/tochgif/rubyconf_ph_2016

3f8fcddf7ab5d1bd90b0a0a9adfd6527?s=128

Christophe Philemotte

April 09, 2016
Tweet

Transcript

  1. Building a cross-platform API CLI in 15 minutes

  2. toch _toch Magandang araw! Ako si Christophe.

  3. None
  4. None
  5. Google Trend of the keywords Web API

  6. None
  7. None
  8. GitHub -> Hub Heroku -> Heroku Toolbelt AWS -> aws-cli

    Trello -> trello_cli Slack -> slack-cli ...
  9. None
  10. Cross Toolchain?

  11. Cross Toolchain? ¯\_(ツ)_/¯

  12. None
  13. (╯°□°)╯︵ ┻━┻ ┬──┬

  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. $ gem install heroku

  22. None
  23. None
  24. None
  25. $ GOOS=linux GOARCH=amd64 go build $ GOOS=windows GOARCH=amd64 go build

    $ GOOS=darwin GOARCH=amd64 go build
  26. None
  27. None
  28. We shouldn't stop there!

  29. + = https://github.com/hone/mruby-cli mruby-cli

  30. → Ruby → Performance → No Require → Binary for

    each platform/arch → Simple to compile & release → CLI apps framework Mruby-cli talk at RubyKaigi 2015 Goals
  31. Team

  32. None
  33. → ISO/IEC 30170:2012 standard → Compatible with Ruby 2.1 core

    API → No Built-in File/Socket/IO → not threadsafe, no Thread → procs/blocks → metaprogramming → monkey patching → literals → easy to bind to C-ABI compatible lib
  34. Gotchas: → no stdlib → native ext have to support

    cross- compilation → no Rubygems, but mrbgems-list
  35. None
  36. None
  37. None
  38. Safe Live Coding: Hello RubyConf Ph

  39. Safe Live Coding: Advanced Scaffold

  40. A real example: ~/my_repo/ $ github_status Success

  41. GitHub Repository: $ git config --get remote.origin.url git@github.com:toch/my_repo.git

  42. Current Branch Name: $ git symbolic-ref HEAD refs/heads/current_branch

  43. Corresponding Pull Request: GET /repos/toch/my_repo/pulls ?head=toch:current_branch

  44. GitHub Status GET /repos/toch/my_repo /commits/<sha_head>/status

  45. Safe Live Coding: GitHub Status

  46. Let's build CLI in Ruby <3! toch _toch hone/mruby-cli toch/mruby-web_api

    toch/github_status