Skip to content

Instantly share code, notes, and snippets.

@etweisberg
Last active April 5, 2021 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etweisberg/5189e27d66b109124c9a2bdbc7d1e1d3 to your computer and use it in GitHub Desktop.
Save etweisberg/5189e27d66b109124c9a2bdbc7d1e1d3 to your computer and use it in GitHub Desktop.
RESTful API example usage for PeptoidDB API
#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