Sha256: 11055e47fcd6b3ea205c2ce4b7b287e40df211cb5abd72c24620025e0787a7d8

Contents?: true

Size: 593 Bytes

Versions: 44

Compression:

Stored size: 593 Bytes

Contents

prepend Respond, Actions
respond.with_json

class VersionedResponse
	def to_json(options = {})
		JSON::dump(self.as_json(options))
	end
	
	# Modelled after http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
	def as_json(options = {})
		if options[:version] == '1'
			{"message" => "Hello World"}
		elsif options[:version] == '2'
			{"message" => "Goodbye World"}
		else
			{}
		end
	end
end

# To get different verions of the response, use:
# Accept: application/json;version=1
# Accept: application/json;version=2
on 'fetch' do
	succeed! content: VersionedResponse.new
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
utopia-2.11.1 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.11.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.10.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.9.5 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.9.3 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.9.2 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.9.1 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.9.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.8.2 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.8.1 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.8.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.7.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.6.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.5.5 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.5.4 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.5.3 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.5.1 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.5.0 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.4.1 spec/utopia/controller/respond_spec/api/controller.rb
utopia-2.4.0 spec/utopia/controller/respond_spec/api/controller.rb