Skip to content

Scripting: Request Variables

ens-bwalts edited this page Feb 5, 2020 · 1 revision

For the following examples, assume you want to make the following request in your script:


https://rest.ensembl.org/lookup/id/ENSG00000157764?content-type=application/json;expand=1

For each language, start by making the following two strings:

  • Make a string of the server (you will use this multiple times).

  • Make another string of the extension with all the parameters.

Make a Request – Python


import requests, sys
server = "https://rest.ensembl.org"
ext = "/lookup/id/ENSG00000157764?expand=1"
r = requests.get(server+ext, headers={ "Accept" : "application/json"})
pprint (r)

Make a Request – R


library(httr)
library(jsonlite)
server <- "https://rest.ensembl.org"
ext <- "/lookup/id/ENSG00000157764?expand=1"
r <- GET(paste(server, ext, sep = ""), accept("application/json"))
r

Make a Request – Perl


use HTTP::Tiny;
use JSON;
my $http = HTTP::Tiny->new();
my $server = "https://rest.ensembl.org";
my $ext = "/lookup/id/ENSG00000157764?expand=1";
my $headers = { 'Accept' => 'application/json' };
my $r = $http->get($server.$ext, {headers => $headers});
print $r;