Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 88 lines (63 sloc) 3.082 kb
19735ca @supernovus First unfinished commit, prior to moving to URI library.
authored
1 HTTP::Client -- Perl 6 library for building HTTP Clients
2 ----------------------------------------------------------
3
4 Inspired by LWP and HTTP::Client from Perl 5, and LWP::Simple
5 from Perl 6, this is a simple class for building HTTP clients
6 using Perl 6.
7
8 It's not based on any of those when it comes to API, but instead
9 offers a flexible syntax that's easy to use, and easy to extend.
10
11 It currently only supports HTTP itself. HTTP+SSL (HTTPS) support
12 is planned for a future version.
13
14 = Usage =
15
16 A simple GET request, without an intermetiary Request object:
17
18 my $client = HTTP::Client.new;
19 my $response = $client.get('http://example.com/web/service');
20 if ($response.success) {
21 say $response.content;
22 }
23
24 A more advanced POST application/x-www-form-urlencoded request:
25
26 my $client = HTTP::Client.new;
27 my $request = $client.post; ## Note we are not setting the URI/URL.
28 $request.url('http://example.com/web/service');
29 ## The following line creates Request variables called query and mode.
30 ## You could also do $request.set-content('query=libwww-perl&mode=dist');
31 ## But I think letting the library build your content for you, is nicer.
32 $request.add-field(:query<libwww-perl>, :mode<dist>);
d780c12 @supernovus Basic functionality in place, now needs testing (and tests...)
authored
33 my $response = $request.run; ## or $client.do-request($request);
19735ca @supernovus First unfinished commit, prior to moving to URI library.
authored
34 ...
35
36 A more advanced POST multipart/form-data request:
37
38 my $client = HTTP::Client.new;
39 my $request = $client.post(:multipart);
40 $request.url('http://example.com/web/service');
41 $request.add-field(:id(37271));
42 $request.add-file(
43 :name("upload"), :filename("file.txt"),
44 :type("text/plain"), :content("hello world...")
45 );
46 my $response = $request.run;
47
48 = Notes =
49
50 As seen above, there is no need to build HTTP::Client::Request objects
51 manually. Just use the appropriate method (get, post, head, put, delete)
52 or use $client.make-request($method); for methods that don't have methods
53 in HTTP::Client (TRACE, OPTIONS, CONNECT, PATCH, DEBUG, etc.)
54
55 As it's name states, this library is specifically for HTTP Clients.
56 If you want something for building HTTP Servers, see HTTP::Easy.
57 If you want something for Request/Reponse objects for your Web Application,
58 see WWW::App. Full disclosure: I wrote both of those libraries too.
59
642f034 @supernovus New version, works around nom bugs, has very basic tests for GET, POS…
authored
60 Also, there are some weird issues with the IO::Socket::INET library in
61 the current Rakudo nom, which are affecting connecting to outside servers.
62 So the tests in the t/ folder currently depend on the HTTP::Easy library,
63 and in particular, the examples/test.p6 script from HTTP::Easy to be running
64 before you run the tests.
65
19735ca @supernovus First unfinished commit, prior to moving to URI library.
authored
66 = Requirements =
67
68 * Rakudo Perl 6 <http://rakudo.org/>
e74386c @supernovus Added HTTP::Status to deps
authored
69 * HTTP::Status <https://github.com/supernovus/perl6-http-status/>
19735ca @supernovus First unfinished commit, prior to moving to URI library.
authored
70 * MIME::Base64 <https://github.com/snarkyboojum/Perl6-MIME-Base64/>
71
d780c12 @supernovus Basic functionality in place, now needs testing (and tests...)
authored
72 It should also require:
73
74 * URI <https://github.com/ihrd/uri/>
75
76 But at the current time, that module is not compiling under "nom" which
77 the rest of this is focused on, so for the time being, I'm using a very
78 limited inline URI grammar instead.
79
19735ca @supernovus First unfinished commit, prior to moving to URI library.
authored
80 = Author =
81
82 Timothy Totten
83
84 = License =
85
86 Artistic License 2.0
87
Something went wrong with that request. Please try again.