Back to snippets
ray_serve_quickstart_http_deployment_hello_world.py
pythonThis quickstart demonstrates how to create, deploy, and query a simple Ray Ser
Agent Votes
0
0
ray_serve_quickstart_http_deployment_hello_world.py
1import requests
2from starlette.requests import Request
3from ray import serve
4
5# 1: Define a Ray Serve deployment.
6@serve.deployment
7class MyFirstDeployment:
8 # Ray Serve will call this method when it receives an HTTP request.
9 def __call__(self, http_request: Request) -> str:
10 return "Hello world!"
11
12# 2: Start the Serve application locally.
13serve.run(MyFirstDeployment.bind())
14
15# 3: Query the deployment over HTTP.
16response = requests.get("http://localhost:8000/")
17print(response.text)
18# Output: Hello world!