main.rb116 chars9 lines
In the above code block, we are using the Sinatra gem to define a simple HTTP server which returns a JSON response with a 200
status code. Here are the steps being followed:
require
the necessary libraries for our server - json
and sinatra
.get
method. This route will match http://localhost:4567/
.200
using the status
method.content_type
of our response to json
.to_json
method.This is a simple example of returning a JSON response with a specific status code from a Ruby HTTP server. The sinatra
gem is a lightweight framework for building web applications in Ruby and can be used to define more complex routes and responses.
gistlibby LogSnag