org.codehaus.enunciate.modules.ruby.library_description.fmt Maven / Gradle / Ivy
Go to download
The Enunciate Ruby module generates the Ruby client code for accessing the Enunciate services.
[#ftl]
[#-- @ftlvariable name="bundle_contains" type="java.lang.String" --]
[#-- @ftlvariable name="sample_resource" type="org.codehaus.enunciate.contract.jaxrs.ResourceMethod" --]
[#-- @ftlvariable name="sample_service_method" type="org.codehaus.enunciate.contract.jaxws.WebMethod" --]
Introduction
The Ruby client-side library defines the Ruby classes that can be (de)serialized to/from JSON.
This is useful for accessing the REST endpoints that are published by this application, but only
those that produce a JSON representation of their resources (content type "application/json").
This library leverages the Ruby JSON Implementation, which is
required in order to use this library.
[#if sample_resource?? && sample_resource.representationMetadata?? && sample_resource.representationMetadata.xmlElement??]
JSON REST Example
require 'net/https'
require 'uri'
//...
//read a resource from a REST url
url = URI.parse("...")
request = Net::HTTP::${sample_resource.httpMethods?first?lower_case?cap_first}.new(url.request_uri)
[#if sample_resource.entityParameter?? && sample_resource.entityParameter.xmlElement??]
input = ${sample_resource.entityParameter.xmlElement.simpleName}.new
//set up the ${sample_resource.entityParameter.xmlElement.simpleName}...
request.body = input.to_json
request['Content-Type'] = "application/json"
[/#if]
http = Net::HTTP.new(url.host, url.port)
//set up additional http stuff...
res = http.start do |ht|
ht.request(request)
end
result = ${sample_resource.representationMetadata.xmlElement.simpleName}.from_json(JSON.parse(res.body))
//handle the result as needed...
[/#if]
© 2015 - 2025 Weber Informatics LLC | Privacy Policy