WADL/WSDL 2.0 for RESTful services in Ruby on Rails

我只是一个虾纸丫 提交于 2019-12-06 14:33:28

The answer is "No"; Rails does not provide a way to do this. WSDL 2.0 is arguably used by nobody, let alone by anybody doing REST (even though it's theoretically possible to a certain degree, its support for RESTful HTTP is very limited; e.g. it doesn't support hypermedia). WADL has strong acceptance problems within the REST community, too; with the exception of the Java Jersey framework, I'm not aware of any implementation.

Yes , Solution for your requirement is installing a Actionwebservice gem in rails , If your using rails 2.3.2 and try installing the Actionwebservice gem using the following command

Step 1 :

 $ gem install datanoise-actionwebservice --source http://gems.github.com

Step 2 : Add the gem to the conf/environment.rb

 config.gem 'datanoise-actionwebservice', :lib => 'actionwebservice'

Step 3 : Generate a webservice

 $ ./script/generate web_service  webservice_name

you could see the generated webservice files in /app/services

Step 4 : Modify your controller

class YourController < ApplicationController
     wsdl_service_name 'webservice_name'
     web_service_api webservice_nameApi
     web_service_scaffold :invocation if Rails.env == 'development'

 def add(name, value)
   Your.create(:name => name, :value => value).id
 end

end

Step 5: Modify your api class in app/services

class WebserviceNameApi < ActionWebService::API::Base
    api_method :add, :expects => [:string, :string], :returns => [:int]

end

Step 6 : You can read the wsdl file

$ ./script/server
$ curl http://localhost:3000/controller/wsdl

You can generate Ruby clients based on your WADL using REST Describe & Compile. You can find very nice detailed documentation about it in Google Documents.

Actually there is one implementation - a gem which can generate WADL from Rails routes: https://github.com/austvik/wadlgen, but it has it's limitations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!