"description": "mammary gland, adenocarcinoma", The dictionary is then dumped back to a string and pretty-printed with useful indentation. The ENCODE server's JSON response is extracted as a Python dictionary using the response.json() method. This script GET's the JSON representation of ENCODE biosample ENCBS000AAA. # Extract the JSON response as a Python dictionary Response = requests.get(url, headers=headers) # This URL locates the ENCODE biosample with accession number ENCBS000AAA # Force return from the server in JSON format Sending a GET request is accomplished here by using the requests.get() method. GET will work without a username and password to fetch publicly-released ENCODE objects. The HTTP GET request is used to retrieve objects from the ENCODE server. A library or module for parsing JSON-structured text and building native data structures.The requests library here for Python is good, and will be used for examples in this documentation. A library or module for your language of choice that supports HTTP.The ENCODE REST API uses GET to transport JSON-formatted information between the server and your scripts. You will then use a library to parse the JSON and construct a native data structure (like a Python dictionary). The resource you GET, using that URL, will be in JSON format. That's all curl does, that's all your browser does, and that's all your scripts will do. The important thing to remember is that each ENCODE object is accessible via a simple URL containing an identifier (like an accession number) for that object. If you can get an object with a curl command, you should be able to get it with your script. To use it with the output of curl, you can simply pipe its output to jq:Īs you develop your scripts, curl can be a valuable testing tool. To pretty-print JSON on the command line, you can use the jq utility, available here. This makes parsing the results of your queries much easier. You can see that even error responses come back in JSON format. You will find curl useful later for debugging your scripts (it always works), so if you don't already have it, you'll want to get it.īy clicking the JSON button, which looks like Make sure you get the SSL and SSH aware version. If you don't have curl, an executable can be downloaded from here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |