Swagger2::Client - A client for talking to a Swagger powered server
Swagger2::Client is a base class for autogenerated classes that can talk to a server using a swagger specification.
Note that this is a DRAFT, so there will probably be bugs and changes.
The input "url" given to "generate" need to point to a valid swagger document.
--- swagger: 2.0 basePath: /api paths: /foo: get: operationId: listPets parameters: - name: limit in: query type: integer responses: 200: { ... }
The swagger specification will the be turned into a sub class of Swagger2::Client, where the "parameters" rules are used to do input validation.
The method name added is a decamelized version of the operationId, which creates a more perl-ish feeling to the API.
use Swagger2::Client; my $ua = Swagger2::Client->generate("file:///path/to/api.json"); # blocking my $pets = $ua->list_pets; # instead of listPets() # non-blocking $ua = $ua->list_pets(sub { my ($ua, $err, $pets) = @_; }); # with arguments, where the key map to the "parameters" name my $pets = $ua->list_pets({limit => 10});
If you want to request a different server than what is specified in the swagger document:
$ua->base_url->host("other.server.com");
$base_url = $self->base_url;
Returns a Mojo::URL object with the base URL to the API.
$ua = $self->ua;
Returns a Mojo::UserAgent object which is used to execute requests.
$client = Swagger2::Client->generate($specification_url);
Returns an object of a generated class, with the rules from the $specification_url.
$specification_url
Note that the class is cached by perl, so loading a new specification from the same URL will not generate a new class.
Copyright (C) 2014-2015, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Swagger2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Swagger2
CPAN shell
perl -MCPAN -e shell install Swagger2
For more information on module installation, please visit the detailed CPAN module installation guide.