- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 08:32 AM
@Aakash Bhandari :
To send a request from a React App to a FastAPI endpoint on a Databricks cluster using a Personal Access Token (PAT), you can use the requests module in Python to make HTTP requests.
Here's an example of how to use requests to send a POST request to your FastAPI endpoint:
import requests
url = "http://0.0.0.0:8084/predict"
headers = {"Authorization": "Bearer <your PAT here>"}
data = {"input": "your input data here"}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
# do something with the result
else:
print("Request failed with status code:", response.status_code)Replace <your PAT here> with your actual Personal Access Token. You can generate a PAT in your Databricks workspace by going to User Settings > Access Tokens and creating a new token with the appropriate permissions.
In this example, the data parameter is a dictionary containing the input data that you want to send to your endpoint. You can modify this dictionary to include any additional parameters that your endpoint requires.
Also, note that the headers parameter includes an Authorization header with the value "Bearer <your PAT here>". This header is required for authenticating with your Databricks cluster using the PAT.
Make sure to modify the url parameter to match the actual address of your FastAPI endpoint. If your Databricks cluster is behind a firewall or network security group, you may need to configure your firewall rules to allow traffic from your local computer to the cluster's IP address and port number.
Hope all these suggestions help you to come to the solution.