Grape では 1 ファイルに API をずらっと書けるけど、 規模が大きくなってくると見通しが悪くなるので、複数ファイルに分割したくなる。 Grape では API が他の API をマウントできるので、 その機能を使ってリソースごとにファイルを分割できる。 以下、サンプル。ヘルパーも別ファイルに切り出してみた。 posts.rb # coding: utf-8 module API class Posts < Grape::API resource :posts do desc "投稿をすべて取得" get do # posts はヘルパーメソッド posts end desc "投稿を1件取得" get ":id" do posts.find(params[:id]) end end end end helpers.rb # coding: utf-8 module API mod