Reynard is an OpenAPI client for Ruby. It operates directly on the OpenAPI specification without the need to generate any source code.
# A Client does not have a fixed state and creating a new
# client will never incur a cost over creating the object
# itself.
reynard = Reynard.new(filename: 'openapi.yml')
Reynard is distributed as a gem called reynard
.
An OpenAPI specification may specify multiple servers. There is no automated way to select the ‘correct’ server so Reynard uses the first one by default.
For example:
servers:
- url: http://production.example.com/v1
- url: http://staging.example.com/v1
Will cause Reynard to choose the production URL.
reynard.url #=> "http://production.example.com/v1"
You can override the base_url
if you want to use a different one.
reynard.base_url('http://test.example.com/v1')
You also have access to all servers in the specification so you can automatically select one however you want.
base_url = @reynard.servers.map(&:url).find do |url|
/staging/.match(url)
end
reynard.base_url(base_url)
Assuming there is an operation called employeeByUuid
you can it as shown below.
employee = reynard.
operation('employeeByUuid').
params(uuid: uuid).
execute
When an operation requires a body, you can add it as structured data.
employee = reynard.
operation('createEmployee').
body(name: 'Sam Seven').
execute
See LICENCE.