Add json() helper

This commit is contained in:
Ryan Cavicchioni 2024-09-04 15:23:53 -05:00
parent 9006678b33
commit 8924d1155c
Signed by: ryanc
SSH Key Fingerprint: SHA256:FEbwJ3JyWHwYNAM8BqctZ/LmHHg1bzfi/huOj7FxlXU

10
app.rb
View File

@ -209,6 +209,16 @@ before do
request.session_options[:skip] = !request.path_info.start_with?("/session")
end
helpers do
def json(obj, opts: nil, pretty: false)
if pretty
JSON.pretty_generate obj, opts:
else
JSON.generate(obj, opts:)
end
end
end
get "/" do
"hello there!\n"
end