[sf-perl] REST-API fail (POST request).
William Michels
wjm1 at caa.columbia.edu
Sun Nov 20 13:02:41 PST 2022
Thank you so much Collin for the quick response!
Well everything seems to be working now. I installed IO::Socket::SSL and
Net::SSLeay as you suggested, and edited the `die` line according to your
specification. Here's the response:
[
{
'is_current' => '1',
'version' => 14,
'release' => '108',
'type' => 'Gene',
'latest' => 'ENSG00000157764.14',
'possible_replacement' => [],
'peptide' => undef,
'id' => 'ENSG00000157764',
'assembly' => 'GRCh38'
},
{
'id' => 'ENSG00000248378',
'assembly' => 'GRCh38',
'latest' => 'ENSG00000248378.1',
'possible_replacement' => [],
'peptide' => undef,
'release' => '108',
'type' => 'Gene',
'is_current' => '1',
'version' => 1
}
]
One slight weirdness: if I edit out both lines `use IO::Socket::SSL` and
`use Net::SSLeay` everything still works. I guess there could be multiple
explanations, the two primary explanations being that 1) something changed
on the server and/or 2) something changed with my Perl5 ecosystem.
Anyway, happy it's working.
Best Regards,
Bill.
On Sun, Nov 20, 2022 at 9:48 AM Collin Seaton <collinseaton at gmail.com>
wrote:
> Hi William,
> You can check your $response for more details on the failure. Specifically:
>
> die "Failed: ", $response->{content}, "\n" unless $response->{success};
>
> This is a guess, based on past work with Perl and web APIs, but you
> probably need to install some modules to support the https protocol. From
> the HTTP::Tiny docs, you'll need IO::Socket::SSL and Net::SSLeay.
> https://metacpan.org/pod/HTTP::Tiny#SSL-SUPPORT
>
> -collin
>
> On Sun, Nov 20, 2022 at 7:38 AM William Michels <wjm1 at caa.columbia.edu>
> wrote:
>
>> Hello,
>>
>> I'm trying to get the example Perl5 code from the bottom of this REST-API
>> page to work:
>>
>> https://rest.ensembl.org/documentation/info/archive_id_post
>>
>> I can get the example curl, wget, and R code to work from the same page,
>> so I know the server (https://rest.ensembl.org) is up and running. Below
>> is the code, cut-and-pasted. I had to install the JSON module. All I get
>> back is the string "Failed!" while curl, wget, and R all return actual
>> data:
>>
>>
>> use strict;
>> use warnings;
>>
>> use HTTP::Tiny;
>>
>> my $http = HTTP::Tiny->new();
>>
>> my $server = 'https://rest.ensembl.org';
>> my $ext = '/archive/id';
>> my $response = $http->request('POST', $server.$ext, {
>> headers => {
>> 'Content-type' => 'application/json',
>> 'Accept' => 'application/json'
>> },
>> content => '{ "id" : ["ENSG00000157764", "ENSG00000248378"] }'
>> });
>>
>> die "Failed!\n" unless $response->{success};
>>
>>
>> use JSON;
>> use Data::Dumper;
>> if(length $response->{content}) {
>> my $hash = decode_json($response->{content});
>> local $Data::Dumper::Terse = 1;
>> local $Data::Dumper::Indent = 1;
>> print Dumper $hash;
>> print "\n";
>> }
>>
>>
>>
>> _______________________________________________
>> SanFrancisco-pm mailing list
>> SanFrancisco-pm at pm.org
>> https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20221120/f6bda2b8/attachment.html>
More information about the SanFrancisco-pm
mailing list