These are chat archives for dry-rb/chat

7th
Jul 2017
Ahmad Musaffa
@musaffa
Jul 07 2017 06:29
@gotar dry-web-blog is just a generated app. There's nothing new in it.
Tim Riley
@timriley
Jul 07 2017 06:44
I haven’t had a chance to make anything yet, I hope I can soon, @musaffa
Ahmad Musaffa
@musaffa
Jul 07 2017 10:16
How do you return a json response with dry-web-roda? Is dry-view appropriate for placing json response code?
Tim Riley
@timriley
Jul 07 2017 11:05
@musaffa yep, you can use the tilt yajl engine and .json.yajl templates
That's one option, anyway. I'm sure there are others.
Ahmad Musaffa
@musaffa
Jul 07 2017 12:27

I've enabled json plugin for roda and put this code:

# lib/dwimiklab_api/articles/views/show.rb
require 'dwimiklab_api/import'

module DwimiklabApi
  module Articles
    module Views
      class Show
        include DwimiklabApi::Import['articles.repository']

        def call(id)
          repository[id]
        end
      end
    end
  end
end

# web/routes/articles.rb
module DwimiklabApi
  class Application
    route 'articles' do |r|
      r.on ':id' do |id|
        r.resolve 'articles.views.show' do |show|
          show.(id).to_hash
        end
      end
    end
  end
end

I've removed dry-view because all I need is some json responses.

Tim Riley
@timriley
Jul 07 2017 21:24
👍🏼