2016年2月3日水曜日
2016年2月1日月曜日
【作業メモ】2016.01.31
Herokuにsinatraで簡単なApiサーバーを作る。
/Gemfile
/Gemfile
source "https://rubygems.org" ruby "2.2.2" gem 'sinatra', '1.4.7'/Procfile
web: bundle exec ruby app.rb -p $PORT/config.rb
web: bundle exec rackup config.ru -p $PORT/app.rb
require 'rubygems'
require 'sinatra'
require 'json'
get "/app" do
json_data = open("settings/shuzo.json") do |io|
JSON.load(io)
end
json_data["items"].each do | item |
content_type :json
if params["id"] == item["id"]
body << item.to_json
end
end
body
end
/settings/shuzo.json
{
"items":[{
"id":"1",
"name":"Kuwako",
"age":"29"
},{
"id":"2",
"name":"Matsuoka",
"age":"48"
}]
}
この辺が参考:https://devcenter.heroku.com/articles/getting-started-with-ruby-o
登録:
コメント (Atom)