.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Swagger2::Client 3pm" .TH Swagger2::Client 3pm "2016-04-17" "perl v5.22.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Swagger2::Client \- A client for talking to a Swagger powered server .SH "DESCRIPTION" .IX Header "DESCRIPTION" Swagger2::Client is a base class for autogenerated classes that can talk to a server using a swagger specification. .PP Note that this is a \s-1DRAFT,\s0 so there will probably be bugs and changes. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .SS "Swagger specification" .IX Subsection "Swagger specification" The input \*(L"url\*(R" given to \*(L"generate\*(R" need to point to a valid swagger document. .PP .Vb 10 \& \-\-\- \& swagger: 2.0 \& basePath: /api \& paths: \& /foo: \& get: \& operationId: listPets \& parameters: \& \- name: limit \& in: query \& type: integer \& responses: \& 200: { ... } .Ve .SS "Client" .IX Subsection "Client" The swagger specification will the be turned into a sub class of Swagger2::Client, where the \*(L"parameters\*(R" rules are used to do input validation. .PP .Vb 2 \& use Swagger2::Client; \& $ua = Swagger2::Client\->generate("file:///path/to/api.json"); \& \& # blocking (will croak() on error) \& $pets = $ua\->listPets; \& \& # blocking (will not croak() on error) \& $ua\->return_on_error(1); \& $pets = $ua\->listPets; \& \& # non\-blocking \& $ua = $ua\->listPets(sub { my ($ua, $err, $pets) = @_; }); \& \& # with arguments, where the key map to the "parameters" name \& $pets = $ua\->listPets({limit => 10}); .Ve .PP The method name added will both be the original \f(CW\*(C`operationId\*(C'\fR, but a \*(L"snake case\*(R" version will also be added. Example: .PP .Vb 3 \& "operationId": "listPets" \& => $client\->listPets() \& => $client\->list_pets() .Ve .SS "Customization" .IX Subsection "Customization" If you want to request a different server than what is specified in the swagger document: .PP .Vb 1 \& $ua\->base_url\->host("other.server.com"); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .SS "base_url" .IX Subsection "base_url" .Vb 1 \& $base_url = $self\->base_url; .Ve .PP Returns a Mojo::URL object with the base \s-1URL\s0 to the \s-1API.\s0 .SS "ua" .IX Subsection "ua" .Vb 1 \& $ua = $self\->ua; .Ve .PP Returns a Mojo::UserAgent object which is used to execute requests. .SH "METHODS" .IX Header "METHODS" .SS "generate" .IX Subsection "generate" .Vb 2 \& $client = Swagger2::Client\->generate(Swagger2\->new($specification_url)); \& $client = Swagger2::Client\->generate($specification_url); .Ve .PP Returns an object of a generated class, with the rules from the \&\f(CW$specification_url\fR. .PP Note that the class is cached by perl, so loading a new specification from the same \s-1URL\s0 will not generate a new class. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2014\-2015, Jan Henning Thorsen .PP This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. .SH "AUTHOR" .IX Header "AUTHOR" Jan Henning Thorsen \- \f(CW\*(C`jhthorsen@cpan.org\*(C'\fR