What is Application Programming Interface(API)?

        Application Programming Interface(API) is a set of rules and conventions that define how software components interact with each other. It allows different applications, services, or systems to communicate, exchange data, and invoke functionalities.API defines how to request and respond to data, and provides a set of predefined operations and parameters that developers can use to access and manipulate the functionalities provided by other applications or services. Web API, for example, is a type of API based on the HTTP protocol, often using JSON or XML format for data exchange. Developers can access these APIs by sending HTTP requests and receive the returned data as a response.


Application Programming Interface(API) Script Code?

        The API interface receives three files: compound sequence, protein sequence, and protein structure. These files are sent to the backend code via the HTTP protocol using a POST request with JSON data type. The backend code then processes the files in bulk and returns the results.

                                        
import requests
import json

# Retrieve compound sequence (Open and retrieve content based on your file address)
with open('ProteinFiles/2023-11-13 07-43-42/compound.smi', 'r') as file:
    compound_sequence = file.read().replace('\n', '')

# Retrieve protein sequence (Open and retrieve content based on your file address)
with open('ProteinFiles/2023-11-13 07-43-42/protein.fasta', 'r') as file:
    protein_sequence = file.read().replace('\n', '')
    
# Retrieve protein structure (Open and retrieve content based on your file address)
with open('ProteinFiles/2023-11-13 07-43-42/protein_structure.pdb', 'r') as file:
    protein_structure = file.read()

# Define the data to be sent (compound sequence, protein sequence, protein structure)
data = {
    "compound_sequence": compound_sequence,
    "protein_sequence": protein_sequence,
    "protein_structure": protein_structure
}

# Convert the data to JSON format
json = json.dumps(data)

# Set the URL of the API endpoint
url = 'http://39.106.7.26:8000/Drug-Online/api'

# Send a POST request and provide the data
response = requests.post(url, json)

# Print the value returned by the server
print(response.json())