Skip to content

Requests should be JSON encoded #1

@screeminlemur

Description

@screeminlemur

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions