10 my ($class, $host, $port, $options) = @_;
12 my $ua = LWP::UserAgent->new;
20 base_uri => "http://$host:$port/",
24 sub ua { shift->{ua} }
25 sub base { shift->{base_uri} }
28 my ($self, $method, $uri, $content) = @_;
30 my $full_uri = $self->base . $uri;
33 if (defined $content) {
34 #Content-Type: application/json
36 $req = HTTP::Request->new( $method, $full_uri, undef, encode_json $content );
37 $req->header('Content-Type' => 'application/json');
39 $req = HTTP::Request->new( $method, $full_uri );
42 my $response = $self->ua->request($req);
44 if ($response->is_success) {
45 return decode_json $response->content;
47 die($response->status_line . ":" . $response->content);
52 my ($self, $url) = @_;
54 $self->request(DELETE => $url);
58 my ($self, $url) = @_;
61 $self->request(GET => $url);
65 my ($self, $url, $json) = @_;
68 $self->request(PUT => $url, $json);
72 my ($self, $url, $json) = @_;
74 $self->request(POST => $url, $json);