- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 05:55 AM
@Aakash Bhandari :
You are correct that if you try to hit http://0.0.0.0:8080 from your React App, it will look for the service running on the local machine's localhost and not on the Databricks cluster.
To address this, you need to specify the URL of the cluster's FastAPI endpoint in the request. This URL will typically be of the form https://<databricks-instance-name>.cloud.databricks.com:443/<path-to-your-endpoint>.
Here's an example code snippet that shows how to make a POST request to a FastAPI endpoint hosted on a Databricks cluster:
import requests
import json
# Replace <databricks-instance-name> with the name of your Databricks instance
url = "https://<databricks-instance-name>.cloud.databricks.com:443/predict"
# Replace <token> with your Databricks Personal Access Token
headers = {"Authorization": f"Bearer <token>"}
# Example payload for the POST request
payload = {"data": {"age": 35, "income": 45000}}
# Send the request to the FastAPI endpoint
response = requests.post(url, headers=headers, data=json.dumps(payload))
# Print the response
print(response.json())Note that you need to replace <databricks-instance-name> with the name of your Databricks instance and <token> with your Databricks Personal Access Token. You also need to replace the example payload with your own JSON payload for the POST request.