Coder Social home page Coder Social logo

raku-http-client's Introduction

HTTP::Client -- Perl 6 library for building HTTP Clients
-------------------------------------------------------------------------------

NOTE: This library is going to have a major rewrite coming up shortly.
      A lot of things will be gutted and overhauled.
      Stay tuned for more details!

-------------------------------------------------------------------------------

Inspired by LWP and HTTP::Client from Perl 5, and LWP::Simple
from Perl 6, this is a simple class for building HTTP clients 
using Perl 6.

It's not based on any of those when it comes to API, but instead
offers a flexible syntax that's easy to use, and easy to extend.

It currently only supports HTTP itself. HTTP+SSL (HTTPS) support
is planned for a future version.

= Usage =

A simple GET request, without an intermetiary Request object:

  my $client = HTTP::Client.new;
  my $response = $client.get('http://example.com/web/service');
  if ($response.success) {
    say $response.content;
  }

A more advanced POST application/x-www-form-urlencoded request:

  my $client = HTTP::Client.new;
  my $request = $client.post; ## Note we are not setting the URI/URL.
  $request.url('http://example.com/web/service');
  ## The following line creates Request variables called query and mode.
  ## You could also do $request.set-content('query=libwww-perl&mode=dist');
  ## But I think letting the library build your content for you, is nicer.
  $request.add-field(:query<libwww-perl>, :mode<dist>);
  my $response = $request.run; ## or $client.do-request($request);
  ...

A more advanced POST multipart/form-data request:

  my $client = HTTP::Client.new;
  my $request = $client.post(:multipart);
  $request.url('http://example.com/web/service');
  $request.add-field(:id(37271));
  $request.add-file(
    :name("upload"),     :filename("file.txt"), 
    :type("text/plain"), :content("hello world...")
  );
  my $response = $request.run;

= Notes =

As seen above, there is no need to build HTTP::Client::Request objects
manually. Just use the appropriate method (get, post, head, put, delete)
or use $client.make-request($method); for methods that don't have methods
in HTTP::Client (TRACE, OPTIONS, CONNECT, PATCH, DEBUG, etc.)

As it's name states, this library is specifically for HTTP Clients.
If you want something for building HTTP Servers, see HTTP::Easy.
If you want something for Request/Reponse objects for your Web Application, 
see WWW::App. Full disclosure: I wrote both of those libraries too.

Also, there are some weird issues with the IO::Socket::INET library in
the current Rakudo nom, which are affecting connecting to outside servers.
So the tests in the t/ folder currently depend on the HTTP::Easy library,
and in particular, the examples/test.p6 script from HTTP::Easy to be running
before you run the tests.

= Requirements =

* Rakudo Perl 6      <http://rakudo.org/>
* HTTP::Status       <https://github.com/supernovus/perl6-http-status/>
* MIME::Base64       <https://github.com/snarkyboojum/Perl6-MIME-Base64/>

It should also require:

* URI                <https://github.com/ihrd/uri/>

But at the current time, that module is not compiling under "nom" which
the rest of this is focused on, so for the time being, I'm using a very
limited inline URI grammar instead.

= Author =

Timothy Totten

= License =

Artistic License 2.0

raku-http-client's People

Contributors

perljedi avatar retupmoca avatar supernovus avatar zostay avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.