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

William Michels wjm1 at caa.columbia.edu
Sun Nov 20 07:37:43 PST 2022


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";
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20221120/b5c46ead/attachment.html>


More information about the SanFrancisco-pm mailing list