Move defaults: {format: :json}
and the common only
options at namespace level. Namespace have them as an option.
namespace :api, defaults: { format: :json }, only: [:index, :show, :update] do
namespace :v1 do
resources :users
resources :items, only: [:index, :show, :update, :destroy]
resources :posts
resources :comments
resources :flags, only: [:index, :show, :update, :create]
end
end