$30 off During Our Annual Pro Sale. View Details »

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

Christophe Philemotte

April 09, 2016

More Decks by Christophe Philemotte

Other Decks in Programming


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

    View Slide

  2. toch
    Magandang araw!
    Ako si Christophe.

    View Slide

  3. View Slide

  4. View Slide

  5. Google Trend of the keywords Web API

    View Slide

  6. View Slide

  7. View Slide

  8. GitHub -> Hub
    Heroku -> Heroku Toolbelt
    AWS -> aws-cli
    Trello -> trello_cli
    Slack -> slack-cli

    View Slide

  9. View Slide

  10. Cross Toolchain?

    View Slide

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

    View Slide

  12. View Slide

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

    View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. $ gem install heroku

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. $ GOOS=linux GOARCH=amd64 go build
    $ GOOS=windows GOARCH=amd64 go build
    $ GOOS=darwin GOARCH=amd64 go build

    View Slide

  26. View Slide

  27. View Slide

  28. We shouldn't
    stop there!

    View Slide

  29. + =

    View Slide

  30. → Ruby
    → Performance
    → No Require
    → Binary for each platform/arch
    → Simple to compile & release
    → CLI apps framework
    Mruby-cli talk at RubyKaigi 2015

    View Slide

  31. Team

    View Slide

  32. View Slide

  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

    View Slide

  34. Gotchas:
    → no stdlib
    → native ext have to support cross-
    → no Rubygems, but mrbgems-list

    View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. Safe Live Coding:
    Hello RubyConf Ph

    View Slide

  39. Safe Live Coding:
    Advanced Scaffold

    View Slide

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

    View Slide

  41. GitHub Repository:
    $ git config --get remote.origin.url
    [email protected]:toch/my_repo.git

    View Slide

  42. Current Branch Name:
    $ git symbolic-ref HEAD

    View Slide

  43. Corresponding Pull Request:
    GET /repos/toch/my_repo/pulls

    View Slide

  44. GitHub Status
    GET /repos/toch/my_repo

    View Slide

  45. Safe Live Coding:
    GitHub Status

    View Slide

  46. Let's build CLI in Ruby <3!

    View Slide