-
Notifications
You must be signed in to change notification settings - Fork 63
Scripting: Decode Responses
Content-type
and Accept
HTTP allows the serving of different representations of a resource based on client preferences.
Content-type
and Accept
headers are how servers and clients negotiate what format they will communicate with. Examples are text/html
, text/plain
, application/json
, image/png
, etc.
The returned content-types can be specified in the header as accept (you will need to use content-type in URLs).
The endpoint documentation pages list allowed content-types.
This page lists how you specify output formats:
https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
Here are some decoding examples in Python, Perl and R.
In most cases you will be using JSON formatted responses.
Most languages have JSON parsers that return the data as a structure.
In Python, pretty print (pprint
) will give you a more human readable format.
decoded = r.json()
pprint (decoded)
In R prettify will give you a more human readable format.
decoded = content(r, "text")
prettify (decoded)
In Perl Data::dumper
(dumper) will give you a more human readable format.
my $decoded = Dumper decode_json($r->{content});
print $decoded;