templates/api/hello_world.rb in wd_sinatra-1.0.6 vs templates/api/hello_world.rb in wd_sinatra-2.0.0
- old
+ new
@@ -1,29 +1,36 @@
describe_service "/hello_world" do |service|
- service.formats :json
+ service.formats :json, :xml
service.http_verb :get
service.disable_auth # on by default
+ # DOCUMENTATION
+ service.documentation do |doc|
+ doc.overall "Be polite and say hello"
+ doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
+ end
+
# INPUT
- service.param.string :name, :default => 'World'
+ service.params do |p|
+ p.string :name, :default => 'World'
+ end
# OUTPUT
service.response do |response|
response.object do |obj|
obj.string :message, :doc => "The greeting message sent back. Defaults to 'World'"
obj.datetime :at, :doc => "The timestamp of when the message was dispatched"
end
end
- # DOCUMENTATION
- service.documentation do |doc|
- doc.overall "This service provides a simple hello world implementation example."
- doc.param :name, "The name of the person to greet."
- doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
- end
-
# ACTION/IMPLEMENTATION
service.implementation do
- {:message => "Hello #{params[:name]}", :at => Time.now}.to_json
+ data = {:message => "Hello #{params[:name]}", :at => Time.now}
+ case env["wd.format"]
+ when :json
+ data.to_json
+ when :xml
+ # data.to_xml # serialize to xml
+ end
end
end