Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to serve yaml file with sinatra? (not download)

I have a basic Sinatra app, I’d like to serve a yaml file so that it can be read by a gem via http.

I’m just able to download it:

get '/download' do
  send_file './en.yml', :filename => 'en.yml', :type => 'text/yaml'
end

But how can I just serve it without downloading?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Goal is that a gem makes an http request to obtain the content of this endpoint.

>Solution :

Any reason you can’t convert the YAML to JSON and serve that?

require 'json'
require 'sinatra'
require 'sinatra/json' # from sinatra-contrib
require 'yaml'

get '/download' do
  json YAML.safe_load(File.read('en.yml'))
end
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading