require 'sinatra' require 'json' # Configure Sinatra set :port, ENV['PORT'] || 4567 set :bind, '0.0.0.0' # Array of creative "no" responses NO_RESPONSES = [ "No", "Nope", "Absolutely not", "Not a chance", "Never", "No way", "Negative", "Not happening", "Nah", "No siree", "Not today", "Dream on", "Over my dead body", "When pigs fly", "Not in a million years", "Forget about it", "No dice", "Not on your life", "Fat chance", "No can do" ].freeze # Helper method to get a random "no" def get_no_response NO_RESPONSES.sample end # Root endpoint - returns HTML by default get '/' do no_response = get_no_response case request.accept.first&.to_s when /application\/json/ content_type :json { answer: no_response, timestamp: Time.now.iso8601 }.to_json else content_type :html erb :index, locals: { no_response: no_response } end end # Explicit JSON endpoint get '/api/no' do content_type :json { answer: get_no_response, timestamp: Time.now.iso8601, service: "No as a Service", version: "1.0.0" }.to_json end # Health check endpoint get '/health' do content_type :json { status: "healthy", timestamp: Time.now.iso8601 }.to_json end # Catch-all route for any other endpoint get '/*' do no_response = get_no_response case request.accept.first&.to_s when /application\/json/ content_type :json { answer: no_response, timestamp: Time.now.iso8601 }.to_json else content_type :html erb :index, locals: { no_response: no_response } end end __END__ @@index
The definitive API for negative responses
JSON API: GET /api/no
Accept JSON: curl -H "Accept: application/json" /
Health Check: GET /health