Returning JSON from a Sinatra endpoint is really easy. You just have to to the following :
require 'sinatra'
require 'json'
get '/hi' do
# Specify the content type to return, json
content_type :json
{ song: "Wake me Up" }.to_json
end
If you want to configure it for all your routes :
require 'sinatra'
require 'json'
before do
content_type :json
end
get '/hi' do
{ song: "Wake me Up" }.to_json
end
Hope it helps ;)
Tibo