RESTful API example usage for PeptoidDB API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import requests and json modules | |
import requests | |
import json | |
#Retrieve all peptoids in the database | |
url='https://databank.peptoids.org/api' | |
allPeptoids = json.dumps(requests.get(url+'/peptoids').json(),indent=2) #retrieve JSON of all peptoid identifiers and their routes | |
print(f''' | |
---------------------- | |
Request 1: [/peptoids] | |
---------------------- | |
{allPeptoids} | |
''') | |
#Retrieve data on specific peptoid | |
identifier = '13AB1-6-C' #peptoid identifier code | |
peptoidInformation = json.dumps(requests.get(url+f"/peptoids/{identifier}").json(),indent=2) | |
print(f''' | |
-------------------------------- | |
Request 2: [/peptoids/{identifier}] | |
-------------------------------- | |
{peptoidInformation}''') | |
peptoidResidues = json.dumps(requests.get(url+f"/peptoids/{identifier}/residues").json(),indent=2) | |
print(f''' | |
----------------------------------------- | |
Request 3: [/peptoids/{identifier}/residues] | |
----------------------------------------- | |
{peptoidResidues}''') | |
peptoidAuthors = json.dumps(requests.get(url+f"/peptoids/{identifier}/authors").json(),indent=2) | |
print(f''' | |
---------------------------------------- | |
Request 4: [/peptoids/{identifier}/authors] | |
---------------------------------------- | |
{peptoidAuthors}''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment