Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created May 30, 2013 05:03
Show Gist options
  • Save rummelonp/5675823 to your computer and use it in GitHub Desktop.
Save rummelonp/5675823 to your computer and use it in GitHub Desktop.
Grape gem 取り敢えず
# -*- coding: utf-8 -*-
require 'grape'
module Cat
class API < Grape::API
prefix :api
resource :cats do
get ":id" do
{
:id => params[:id],
:name => "猫#{params[:id]}",
:cry => "にゃーん",
}
end
end
end
end
run Cat::API
@rummelonp
Copy link
Author

$ rackup > /dev/null &

$ curl http://0.0.0.0:9292/api/cats/1.json
{"id":"1","name":"猫1","cry":"にゃーん"}

$ curl http://0.0.0.0:9292/api/cats/1.xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <id>1</id>
  <name>猫1</name>
  <cry>にゃーん</cry>
</hash>

$ curl http://0.0.0.0:9292/api/cats/2.json
{"id":"2","name":"猫2","cry":"にゃーん"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment