[sf-perl] REST-API fail (POST request).

William Michels wjm1 at caa.columbia.edu
Tue Nov 22 10:57:17 PST 2022


Thanks Joe!

As I mentioned in an earlier response, everything started to work after I
installed IO::Socket::SSL and Net::SSLeay.

FWIW, here's my Perl5 info, generally installed with Macports (running on
an ancient MacOS = 10.11.6 El Capitan):

user at mbook:~$ which perl
/opt/local/bin/perl
user at mbook:~$ perl --version

This is perl 5, version 34, subversion 1 (v5.34.1) built for
darwin-thread-multi-2level

Copyright 1987-2022, Larry Wall

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

user at mbook:~$

On Sun, Nov 20, 2022 at 12:35 PM Joseph Brenner <doomvox at gmail.com> wrote:

> Yes, for what it's worth, that code example works for me:
>
> perl /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022nov20/
> rest_api_demo.pl
> [
>   {
>     'possible_replacement' => [],
>     'assembly' => 'GRCh38',
>     'latest' => 'ENSG00000157764.14',
>     'id' => 'ENSG00000157764',
>     'release' => '108',
>     'type' => 'Gene',
>     'is_current' => '1',
>     'version' => 14,
>     'peptide' => undef
>   },
>   {
>     'assembly' => 'GRCh38',
>     'possible_replacement' => [],
>     'release' => '108',
>     'latest' => 'ENSG00000248378.1',
>     'id' => 'ENSG00000248378',
>     'version' => 1,
>     'peptide' => undef,
>     'type' => 'Gene',
>     'is_current' => '1'
>   }
> ]
>
>
> I might suggest playing with "cpanm", aka "cpanminus"-- it's a good,
> no-brainer way of installing perl modules for your own use without
> fussing with sysadmin tasks too much.
>
> https://metacpan.org/pod/App::cpanminus
>
>
>
> On 11/20/22, 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/20221122/2837e6fd/attachment.html>


More information about the SanFrancisco-pm mailing list