-
Notifications
You must be signed in to change notification settings - Fork 2
Requests should be JSON encoded #1
Copy link
Copy link
Open
Description
Hello,
Great start to the module! However I couldn't get it working based on the POD. Upon looking at the make_request() method, there seems to be a discrepancy; the content-type is set to 'application/json' however the content of the request isn't being encoded to JSON anywhere that I can see.
Amending the method as follows worked for me. Hope I'm not missing something simple:
sub make_request {
my ($self, $type, $path, $params) = @_;
die 'please provide a type' unless $type
&& ($type eq 'GET' || $type eq 'POST' || $type eq 'PUT' || $type eq 'DELETE');
die 'please provide a relative path' unless $path && $path !~ m{\A/api};
die 'please provide a HASHREF with parameters' unless $params && ref $params eq 'HASH';
my $method = lc $type;
**my $encoded_content = to_json $params;**
return $self->_ua->$method(
'https://' . $self->{_domain} . '/api/v2/' . $path,
[
($method eq 'post' || $method eq 'put'
? ('Content-Type' => 'application/json') : ()
),
],
**$encoded_content,**
);
}
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels