API-Client
view release on metacpan
or search on metacpan
INSTALL
view on Meta::CPAN
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | details on enabling it in your environment.
Alternatively, if your CPAN shell is set up, you should just be able to do :
% cpan API::Client
As a last resort, you can manually install it. Download the tarball, untar it,
install configure prerequisites (see below), then build it:
% perl Makefile.PL
% make && make test
Then install it:
% make install
On Windows platforms, you should use `dmake` or `nmake`, instead of `make`.
|
INSTALL
view on Meta::CPAN
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | If your perl is system -managed, you can create a local ::lib in your home
directory to install modules to. For details, see the local ::lib documentation:
The prerequisites of this distribution will also have to be installed manually. The
prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated
by running the manual build process described above.
This distribution requires other modules to be installed before this
distribution's installer can be run. They can be found under the
"configure_requires" key of META.yml or the
"{prereqs}{configure}{requires}" key of META.json.
This distribution may require additional modules to be installed after running Makefile.PL.
Look for prerequisites in the following phases:
* to run make, PHASE = build
* to use the module code itself, PHASE = runtime * to run tests, PHASE = test
They can all be found in the "PHASE_requires" key of MYMETA.yml or the
"{prereqs}{PHASE}{requires}" key of MYMETA.json.
API-Client documentation is available as POD.
You can run `perldoc` from a shell to read the documentation:
% perldoc API::Client
For more information on installing Perl modules via CPAN, please see:
|
LICENSE
view on Meta::CPAN
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | software and to any other program whose authors commit to using it.
You can use it for your programs, too. When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
|
LICENSE
view on Meta::CPAN
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program" , below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you" .
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
|
LICENSE
view on Meta::CPAN
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system .
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time . Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
LICENSE
view on Meta::CPAN
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | The hypothetical commands `show w ' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer ( if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2019 by Al Newkirk.
This is free software, licensed under:
|
LICENSE
view on Meta::CPAN
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | - "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
|
LICENSE
view on Meta::CPAN
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | 4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
|
META.json
view on Meta::CPAN
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | "license" : [
"perl_5"
],
"meta-spec" : {
"version" : 2
},
"name" : "API-Client" ,
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Data::Object::Class" : "2.02" ,
"Data::Object::ClassHas" : "2.01" ,
"Data::Object::Role::Buildable" : "0.03" ,
"Data::Object::Role::Stashable" : "2.01" ,
"Data::Object::Role::Throwable" : "2.01" ,
"FlightRecorder" : "0.03" ,
"Mojolicious" : "8.35" ,
"perl" : "5.014" ,
"routines" : "0" ,
"strict" : "0" ,
"warnings" : "0"
}
},
"test" : {
"requires" : {
"Data::Object::Class" : "2.02" ,
"Data::Object::ClassHas" : "2.01" ,
"Data::Object::Role::Buildable" : "0.03" ,
"Data::Object::Role::Stashable" : "2.01" ,
"Data::Object::Role::Throwable" : "2.01" ,
"FlightRecorder" : "0.03" ,
"Mojolicious" : "8.35" ,
"Test::Auto" : "0.10" ,
"perl" : "5.014" ,
"routines" : "0" ,
"strict" : "0" ,
"warnings" : "0"
}
}
},
"release_status" : "stable" ,
"resources" : {
"repository" : {
"type" : "git" ,
}
},
"version" : "0.12" ,
"x_authority" : "cpan:AWNCORP" ,
"x_contributors" : [
"Al Newkirk <anewkirk@ana.io>"
],
"x_generated_by_perl" : "v5.26.1" ,
"x_serialization_backend" : "Cpanel::JSON::XS version 4.19" ,
"x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later"
}
|
META.yml
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | ---
abstract: 'HTTP API Thin-Client Abstraction'
author:
- 'Al Newkirk <awncorp@cpan.org>'
build_requires:
Data::Object::Class: '2.02'
Data::Object::ClassHas: '2.01'
Data::Object::Role::Buildable: '0.03'
Data::Object::Role::Stashable: '2.01'
Data::Object::Role::Throwable: '2.01'
FlightRecorder: '0.03'
Mojolicious: '8.35'
Test::Auto: '0.10'
perl: '5.014'
routines: '0'
strict: '0'
warnings: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.014, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
version: '1.4'
name: API-Client
requires:
Data::Object::Class: '2.02'
Data::Object::ClassHas: '2.01'
Data::Object::Role::Buildable: '0.03'
Data::Object::Role::Stashable: '2.01'
Data::Object::Role::Throwable: '2.01'
FlightRecorder: '0.03'
Mojolicious: '8.35'
perl: '5.014'
routines: '0'
strict: '0'
warnings: '0'
resources:
version: '0.12'
x_authority: cpan:AWNCORP
x_contributors:
- 'Al Newkirk <anewkirk@ana.io>'
x_generated_by_perl: v5.26.1
x_serialization_backend: 'YAML::Tiny version 1.73'
x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later'
|
README
view on Meta::CPAN
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | HTTP API Thin-Client Abstraction
SYNOPSIS
DESCRIPTION
This package provides an abstraction and method for rapidly developing HTTP API clients. While this module can be used to interact with APIs
directly, API::Client was designed to be consumed (subclassed) by
higher-level purpose-specific API clients.
THIN CLIENT
The thin API client library is advantageous as it has complete API
coverage and can easily adapt to changes in the API with minimal
effort. As a thin-client superclass, this module does not map specific
HTTP requests to specific routines, nor does it provide parameter
validation, pagination, or other conventions found in typical API
client implementations; Instead, it simply provides a simple and
consistent mechanism for dynamically generating HTTP requests.
Additionally, this module has support for debugging and retrying API
calls as well as throwing exceptions when 4xx and 5xx server response
codes are returned.
INTEGRATES
Data::Object::Role::Buildable
Data::Object::Role::Stashable
|
README
view on Meta::CPAN
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | Types::Standard
SCENARIOS
This package supports the following scenarios: building
my $resource = $client ->resource( 'get' );
my $get = $client ->resource( 'get' )->dispatch;
my $head = $client ->resource( 'head' )->dispatch(
method => 'head'
);
my $patch = $client ->resource( 'patch' )->dispatch(
method => 'patch'
);
[ $get , $head , $patch ]
Building up an HTTP request is extremely easy, simply call the
"resource" to create a new object instance representing the API
endpoint you wish to issue a request against.
chaining
my $users = $client ->resource( 'users' );
my $user = $client ->resource( 'users' , 'c09e91a' );
my $new_user = $users ->resource( 'c09e91a' );
[ $users , $user , $new_user ]
Because each call to "resource" returns a new object instance
configured with a path (resource locator) based on the supplied
parameters, reuse and request isolation are made simple, i.e., you will
only need to configure the client once in your application.
creating
my $tx1 = $client ->resource( 'post' )->create(
json => { active => 1}
);
my $tx2 = $client ->resource( 'post' )->dispatch(
method => 'post' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might create a new API resource.
deleting
my $tx1 = $client ->resource( 'delete' )-> delete (
json => { active => 1}
);
my $tx2 = $client ->resource( 'delete' )->dispatch(
method => 'delete' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might delete a new API resource.
fetching
my $tx1 = $client ->resource( 'get' )->fetch(
query => { active => 1}
);
my $tx2 = $client ->resource( 'get' )->dispatch(
method => 'get' ,
query => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might fetch an API resource.
subclassing
sub auth {
|
README
view on Meta::CPAN
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | sub base {
}
my $hookbin = Hookbin->new;
This package was designed to be subclassed and provides hooks into the client building and request dispatching processes. Specifically, there
are three useful hooks (i.e. methods, which if present are used to
build up the client object and requests), which are, the auth hook,
which should return a Tuple[Str, Str] which is used to configure the
basic auth header, the base hook which should return a Tuple[Str] which
is used to configure the base URL, and the headers hook, which should
return a ArrayRef[Tuple[Str, Str]] which are used to configure the HTTP
request headers.
transacting
my $tx1 = $client ->resource( 'patch' )->patch(
json => { active => 1}
);
my $tx2 = $client ->resource( 'patch' )->dispatch(
method => 'patch' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
An HTTP request is only issued when the "dispatch" method is called,
directly or indirectly. Those calls return a Mojo::Transaction object
which provides access to the request and response objects.
updating
my $tx1 = $client ->resource( 'put' )->update(
json => { active => 1}
);
my $tx2 = $client ->resource( 'put' )->dispatch(
method => 'put' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might update a new API resource.
ATTRIBUTES
This package has the following attributes:
debug
debug(Bool)
This attribute is read -only, accepts (Bool) values , and is optional.
|
README
view on Meta::CPAN
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | This attribute is read -only, accepts (Str) values , and is optional.
METHODS
create
create(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The create method issues a POST request to the API resource represented
by the object.
create example
$client ->resource( 'post' )->create(
json => { active => 1}
);
delete
delete (Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The delete method issues a DELETE request to the API resource
represented by the object.
delete example
$client ->resource( 'delete' )-> delete ;
dispatch
dispatch(Str : $method = 'get' , Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The dispatch method issues a request to the API resource represented by
the object.
dispatch example
$client ->resource( 'get' )->dispatch;
dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , body => 'active=1'
);
dispatch example
$client ->resource( 'get' )->dispatch(
method => 'get' , query => { active => 1}
);
dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , json => { active => 1}
);
dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , form => { active => 1}
);
dispatch example
$client ->resource( 'put' )->dispatch(
method => 'put' , json => { active => 1}
);
dispatch example
$client ->resource( 'patch' )->dispatch(
method => 'patch' , json => { active => 1}
);
dispatch example
$client ->resource( 'delete' )->dispatch(
method => 'delete' , json => { active => 1}
);
fetch
fetch(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The fetch method issues a GET request to the API resource represented
by the object.
fetch example
$client ->resource( 'get' )->fetch;
patch
patch(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The patch method issues a PATCH request to the API resource represented
by the object.
patch example
$client ->resource( 'patch' )->patch(
json => { active => 1}
);
prepare
prepare(Object $ua , Object $tx , Any %args ) : Object
The prepare method acts as a before hook triggered before each request
where you can modify the transactor objects.
|
README
view on Meta::CPAN
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
$client ->prepare(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
process
process(Object $ua , Object $tx , Any %args ) : Object
The process method acts as an after hook triggered after each response
where you can modify the transactor objects.
process example
$client ->process(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
resource
resource(Str @segments ) : Object
The resource method returns a new instance of the object for the API
resource endpoint specified.
resource example
$client ->resource( 'status' , 200);
serialize
serialize() : HashRef
The serialize method serializes and returns the object as a hashref.
serialize example
$client ->serialize;
update
update(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The update method issues a PUT request to the API resource represented
by the object.
update example
$client ->resource( 'put' )->update(
json => { active => 1}
);
AUTHOR
Al Newkirk, awncorp @cpan .org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
|
README.md
view on Meta::CPAN
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | HTTP API Thin-Client Abstraction
This package provides an abstraction and method for rapidly developing HTTP API clients. While this module can be used to interact with APIs directly,
API::Client was designed to be consumed (subclassed) by higher-level
purpose-specific API clients.
The thin API client library is advantageous as it has complete API coverage and
can easily adapt to changes in the API with minimal effort. As a thin-client
superclass, this module does not map specific HTTP requests to specific
routines, nor does it provide parameter validation, pagination, or other
conventions found in typical API client implementations; Instead, it simply
provides a simple and consistent mechanism for dynamically generating HTTP
requests. Additionally, this module has support for debugging and retrying API
calls as well as throwing exceptions when 4xx and 5xx server response codes are
returned.
|
README.md
view on Meta::CPAN
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | This package supports the following scenarios:
my $resource = $client ->resource( 'get' );
my $get = $client ->resource( 'get' )->dispatch;
my $head = $client ->resource( 'head' )->dispatch(
method => 'head'
);
my $patch = $client ->resource( 'patch' )->dispatch(
method => 'patch'
);
[ $get , $head , $patch ]
Building up an HTTP request is extremely easy, simply call the [ "resource" ](
create a new object instance representing the API endpoint you wish to issue a
request against.
my $users = $client ->resource( 'users' );
my $user = $client ->resource( 'users' , 'c09e91a' );
my $new_user = $users ->resource( 'c09e91a' );
[ $users , $user , $new_user ]
Because each call to [ "resource" ](
a path (resource locator) based on the supplied parameters, reuse and request
isolation are made simple, i.e., you will only need to configure the client
once in your application.
my $tx1 = $client ->resource( 'post' )->create(
json => { active => 1}
);
my $tx2 = $client ->resource( 'post' )->dispatch(
method => 'post' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might create a new API resource.
my $tx1 = $client ->resource( 'delete' )-> delete (
json => { active => 1}
);
my $tx2 = $client ->resource( 'delete' )->dispatch(
method => 'delete' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might delete a new API resource.
my $tx1 = $client ->resource( 'get' )->fetch(
query => { active => 1}
);
my $tx2 = $client ->resource( 'get' )->dispatch(
method => 'get' ,
query => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might fetch an API resource.
sub auth {
|
README.md
view on Meta::CPAN
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | sub base {
}
my $hookbin = Hookbin->new;
This package was designed to be subclassed and provides hooks into the client building and request dispatching processes. Specifically, there are three
useful hooks (i.e. methods, which if present are used to build up the client
object and requests), which are, the `auth` hook, which should return a
`Tuple[Str, Str]` which is used to configure the basic auth header, the
`base` hook which should return a `Tuple[Str]` which is used to configure the
base URL, and the `headers` hook, which should return a
`ArrayRef[Tuple[Str, Str]]` which are used to configure the HTTP request
headers.
my $tx1 = $client ->resource( 'patch' )->patch(
json => { active => 1}
);
my $tx2 = $client ->resource( 'patch' )->dispatch(
method => 'patch' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
An HTTP request is only issued when the [ "dispatch" ](
access to the `request` and `response` objects.
my $tx1 = $client ->resource( 'put' )->update(
json => { active => 1}
);
my $tx2 = $client ->resource( 'put' )->dispatch(
method => 'put' ,
json => { active => 1}
);
[ $tx1 , $tx2 ]
This example illustrates how you might update a new API resource.
This package has the following attributes:
debug(Bool)
This attribute is read -only, accepts `(Bool)` values , and is optional.
|
README.md
view on Meta::CPAN
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | This attribute is read -only, accepts `(Str)` values , and is optional.
create(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The create method issues a `POST` request to the API resource represented by
the object.
- create example
$client ->resource( 'post' )->create(
json => { active => 1}
);
delete (Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The delete method issues a `DELETE` request to the API resource represented by
the object.
- delete example
$client ->resource( 'delete' )-> delete ;
dispatch(Str : $method = 'get' , Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The dispatch method issues a request to the API resource represented by the
object.
- dispatch example
$client ->resource( 'get' )->dispatch;
- dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , body => 'active=1'
);
- dispatch example
$client ->resource( 'get' )->dispatch(
method => 'get' , query => { active => 1}
);
- dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , json => { active => 1}
);
- dispatch example
$client ->resource( 'post' )->dispatch(
method => 'post' , form => { active => 1}
);
- dispatch example
$client ->resource( 'put' )->dispatch(
method => 'put' , json => { active => 1}
);
- dispatch example
$client ->resource( 'patch' )->dispatch(
method => 'patch' , json => { active => 1}
);
- dispatch example
$client ->resource( 'delete' )->dispatch(
method => 'delete' , json => { active => 1}
);
fetch(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The fetch method issues a `GET` request to the API resource represented by the
object.
- fetch example
$client ->resource( 'get' )->fetch;
patch(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The patch method issues a `PATCH` request to the API resource represented by
the object.
- patch example
$client ->resource( 'patch' )->patch(
json => { active => 1}
);
prepare(Object $ua , Object $tx , Any %args ) : Object
The prepare method acts as a ` before ` hook triggered before each request where
you can modify the transactor objects.
|
README.md
view on Meta::CPAN
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | $client ->prepare(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
process(Object $ua , Object $tx , Any %args ) : Object
The process method acts as an ` after ` hook triggered after each response where
you can modify the transactor objects.
- process example
$client ->process(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
resource(Str @segments ) : Object
The resource method returns a new instance of the object for the API resource
endpoint specified.
- resource example
$client ->resource( 'status' , 200);
serialize() : HashRef
The serialize method serializes and returns the object as a `hashref`.
- serialize example
$client ->serialize;
update(Any %args ) : InstanceOf[ "Mojo::Transaction" ]
The update method issues a `PUT` request to the API resource represented by
the object.
- update example
$client ->resource( 'put' )->update(
json => { active => 1}
);
Al Newkirk, `awncorp @cpan .org`
Copyright (C) 2011-2019, Al Newkirk, et al.
|
cpanfile
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | requires "Data::Object::Class" => "2.02" ;
requires "Data::Object::ClassHas" => "2.01" ;
requires "Data::Object::Role::Buildable" => "0.03" ;
requires "Data::Object::Role::Stashable" => "2.01" ;
requires "Data::Object::Role::Throwable" => "2.01" ;
requires "FlightRecorder" => "0.03" ;
requires "Mojolicious" => "8.35" ;
requires "perl" => "5.014" ;
requires "routines" => "0" ;
requires "strict" => "0" ;
requires "warnings" => "0" ;
on 'test' => sub {
requires "Data::Object::Class" => "2.02" ;
requires "Data::Object::ClassHas" => "2.01" ;
requires "Data::Object::Role::Buildable" => "0.03" ;
requires "Data::Object::Role::Stashable" => "2.01" ;
requires "Data::Object::Role::Throwable" => "2.01" ;
requires "FlightRecorder" => "0.03" ;
requires "Mojolicious" => "8.35" ;
requires "Test::Auto" => "0.10" ;
requires "perl" => "5.014" ;
requires "routines" => "0" ;
requires "strict" => "0" ;
requires "warnings" => "0" ;
};
on 'configure' => sub {
requires "ExtUtils::MakeMaker" => "0" ;
};
|
lib/API/Client.pm
view on Meta::CPAN
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | }
method delete (Any %args ) {
return $self ->dispatch( %args , method => 'delete' );
}
method dispatch(Str : $method = 'get' , Any %args ) {
my $log = $self ->logger->info( "@{[uc($method)]} @{[$self->url->to_string]}" );
my $result = $self ->execute( %args , method => $method );
$log ->end;
return $result ;
}
method fetch(Any %args ) {
return $self ->dispatch( %args , method => 'get' );
}
method patch(Any %args ) {
return $self ->dispatch( %args , method => 'patch' );
|
lib/API/Client.pm
view on Meta::CPAN
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | $self ->set_identity( $ua , $tx , %args );
return $self ;
}
method process(Object $ua , Object $tx , Any %args ) {
return $self ;
}
method resource(Str @segments ) {
my $url ;
if ( @segments ) {
$url = $self ->url->clone;
$url ->path->merge(
join '/' , '' , @{ $self ->url->path->parts}, @segments
);
}
|
lib/API/Client.pm
view on Meta::CPAN
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | $ua ->on( prepare => fun ( $ua , $tx ) {
$self ->prepare( $ua , $tx , %args );
});
$ua ->max_redirects(0);
$ua ->connect_timeout( $self ->timeout);
$ua ->request_timeout( $self ->timeout);
my ( $ok , $tx , $req , $res );
my $retries = $self ->retries;
for ( my $i = 0; $i < ( $retries || 1); $i ++) {
$tx = $ua ->start( $ua ->build_tx( $method , $url , $headers , @args ));
$self ->process( $ua , $tx , %args );
$req = $tx ->req;
$res = $tx ->res;
$ok = $res ->code ? $res ->code !~ /(4|5)\d\d/ : 0;
if ( $req && $res ) {
my $log = $self ->logger;
my $msg = join " " , "attempt" , ( "#" .( $i +1)), ": $method" , $url ->to_string;
$log ->debug( "req: $msg" )->data({
request => $req ->to_string =~ s/\s*$/\n\n\n/r
});
$log ->debug( "res: $msg" )->data({
response => $res ->to_string =~ s/\s*$/\n\n\n/r
});
$log ->info( "res: $msg [@{[$res->code]}]" );
$log ->output if $self ->debug;
}
last if $ok ;
}
if ( $req && $res && $self ->fatal && ! $ok ) {
my $code = $res ->code;
$self ->stash( tx => $tx );
$self ->throw([ $code , uc "${code}_http_response" ]);
}
return $tx ;
}
1;
|
lib/API/Client.pm
view on Meta::CPAN
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
lib/API/Client.pm
view on Meta::CPAN
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
lib/API/Client.pm
view on Meta::CPAN
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
lib/API/Client.pm
view on Meta::CPAN
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | sub base {
}
my $hookbin = Hookbin->new;
This package was designed to be subclassed and provides hooks into the client building and request dispatching processes. Specifically, there are three
useful hooks (i.e. methods, which if present are used to build up the client
object and requests), which are, the C<auth> hook, which should return a
C<Tuple[Str, Str]> which is used to configure the basic auth header, the
C<base> hook which should return a C<Tuple[Str]> which is used to configure the
base URL, and the C<headers> hook, which should return a
C<ArrayRef[Tuple[Str, Str]]> which are used to configure the HTTP request
headers.
|
lib/API/Client.pm
view on Meta::CPAN
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | |
lib/API/Client.pm
view on Meta::CPAN
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | |
lib/API/Client.pm
view on Meta::CPAN
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | |
t/API_Client.t
view on Meta::CPAN
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
t/API_Client.t
view on Meta::CPAN
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | +=head1 THIN CLIENT
The thin API client library is advantageous as it has complete API coverage and
can easily adapt to changes in the API with minimal effort. As a thin-client
superclass, this module does not map specific HTTP requests to specific
routines, nor does it provide parameter validation, pagination, or other
conventions found in typical API client implementations; Instead, it simply
provides a simple and consistent mechanism for dynamically generating HTTP
requests. Additionally, this module has support for debugging and retrying API
calls as well as throwing exceptions when 4xx and 5xx server response codes are
returned.
|
t/API_Client.t
view on Meta::CPAN
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | }
my $hookbin = Hookbin->new;
|
t/API_Client.t
view on Meta::CPAN
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | $client ->prepare(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
|
t/API_Client.t
view on Meta::CPAN
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
SKIP: {
my $skip_tests = do {
! eval { $tx ->result->is_success};
};
unless ( $skip_tests ) {
my $test = testauto(__FILE__);
my $subs = $test ->standard;
$subs ->synopsis(fun( $tryable ) {
ok my $result = $tryable ->result;
$result
});
$subs ->scenario( 'building' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $get = $result ->[0];
my $head = $result ->[1];
my $patch = $result ->[2];
isnt Scalar::Util::refaddr( $get ), Scalar::Util::refaddr( $head );
isnt Scalar::Util::refaddr( $get ), Scalar::Util::refaddr( $patch );
isnt Scalar::Util::refaddr( $head ), Scalar::Util::refaddr( $patch );
is $get ->req->method, 'get' ;
is $head ->req->method, 'head' ;
is $patch ->req->method, 'patch' ;
});
$subs ->scenario( 'chaining' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $users = $result ->[0];
my $user = $result ->[1];
my $new_user = $result ->[2];
isnt Scalar::Util::refaddr( $users ), Scalar::Util::refaddr( $user );
isnt Scalar::Util::refaddr( $users ), Scalar::Util::refaddr( $new_user );
isnt Scalar::Util::refaddr( $user ), Scalar::Util::refaddr( $new_user );
});
$subs ->scenario( 'fetching' , fun( $tryable ) {
ok my $result = $tryable ->result;
;
});
$subs ->scenario( 'creating' , fun( $tryable ) {
ok my $result = $tryable ->result;
;
});
$subs ->scenario( 'updating' , fun( $tryable ) {
ok my $result = $tryable ->result;
;
});
$subs ->scenario( 'deleting' , fun( $tryable ) {
ok my $result = $tryable ->result;
;
});
$subs ->scenario( 'transacting' , fun( $tryable ) {
ok my $result = $tryable ->result;
;
});
$subs ->scenario( 'subclassing' , fun( $tryable ) {
ok my $result = $tryable ->result;
ok $result ->isa( 'Hookbin' );
ok $result ->isa( 'API::Client' );
is_deeply $result ->auth, [ 'admin' , 'secret' ];
is_deeply $result ->headers, [[ 'Accept' , '*/*' ]];
is $result ->name, 'Hookbin (0.01)' ;
});
$subs ->example(-1, 'create' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'post' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-1, 'delete' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'delete' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, undef ;
is_deeply $json ->{form}, {};
is $json ->{data}, '' ;
$result
});
$subs ->example(-1, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'get' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{args}, {};
$result
});
$subs ->example(-2, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'post' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is $json ->{data}, "active=1" ;
$result
});
$subs ->example(-3, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'get' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{args}, { active => 1};
$result
});
$subs ->example(-4, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'post' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-5, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'post' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is $json ->{data}, "active=1" ;
$result
});
$subs ->example(-6, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'put' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-7, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'patch' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-8, 'dispatch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'delete' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-1, 'fetch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'get' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, undef ;
is_deeply $json ->{form}, undef ;
is $json ->{data}, undef ;
$result
});
$subs ->example(-1, 'patch' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'patch' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
$subs ->example(-1, 'prepare' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
$result
});
$subs ->example(-1, 'process' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
$result
});
$subs ->example(-1, 'resource' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
is $result ->debug, 0;
is $result ->fatal, 0;
like $result ->name, qr/API::Client \(\d.\d\d\)/ ;
is $result ->retries, 0;
is $result ->timeout, 10;
$result
});
$subs ->example(-1, 'serialize' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
is $result ->{debug}, 0;
is $result ->{fatal}, 0;
like $result ->{name}, qr/API::Client \(\d.\d\d\)/ ;
is $result ->{retries}, 0;
is $result ->{timeout}, 10;
$result
});
$subs ->example(-1, 'update' , 'method' , fun( $tryable ) {
ok my $result = $tryable ->result;
my $req = $result ->req;
is lc ( $req ->method), 'put' ;
my $res = $result ->res;
is $res ->code, 200;
my $json = $res ->json;
is $json ->{headers}{ 'Host' }, 'httpbin.org' ;
is $json ->{headers}{ 'Content-Type' }, 'application/json' ;
is_deeply $json ->{json}, { active => 1};
$result
});
}
skip 'Unable to connect to HTTPBin' if $skip_tests ;
}
ok 1 and done_testing;
|