API built with serve and FastAPI only works thru curl or postman but not through another webapp

As the title says, I created an API using Ray Serve and FastAPI. The api works fine when I call it using curl or Postman, but when I call it through a different web application, I don’t get any response back from the api. The request just goes on forever.

Code:

from fastapi import FastAPI
from ray import serve
import ray
from pydantic import BaseModel
import logging
from fastapi.middleware.cors import CORSMiddleware
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware as StarletteCORSMiddleware

logging.basicConfig(level=logging.DEBUG)

app = FastAPI()
origins = [
    "*",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

url = '0.0.0.0'

ray.init(namespace="serve", address="auto")
serve.start(detached=True, http_options={"middlewares": [
    Middleware(
            StarletteCORSMiddleware, allow_origins=["*"], allow_methods=["*"])
]})


class Data(BaseModel):
    text: str
    action: dict


class Text(BaseModel):
    text: str


@serve.deployment
@serve.ingress(app)
class RlClient:
    def __init__(self):
        self.client =  "hello"

    @app.get("/health")
    def health(self):
        return {
            "message": "OK!",
        }

RlClient.deploy()

How do you call it from that other api? if CURL and Postman work the first thing to check would be the call, not the server implementation

I am currently calling it through axios from my NodeJS app. I also tried it with fetch in the browser. I am facing the same issue.

Sorry. Figured my issue out now. It wasn’t anything to do with the ray server. A mistake on my end. Thanks

2 Likes