[Serve] [Doc] Front page update (#13032)

This commit is contained in:
architkulkarni
2020-12-28 10:19:36 -08:00
committed by GitHub
parent 18f5743416
commit 9a0218fb89
5 changed files with 69 additions and 52 deletions
@@ -2,7 +2,7 @@ import ray
from ray import serve
import requests
ray.init(num_cpus=8)
ray.init()
client = serve.start()
@@ -10,13 +10,17 @@ class Counter:
def __init__(self):
self.count = 0
def __call__(self, starlette_request):
def __call__(self, request):
self.count += 1
return {"current_counter": self.count}
return {"count": self.count}
client.create_backend("counter", Counter)
client.create_endpoint("counter", backend="counter", route="/counter")
# Form a backend from our class and connect it to an endpoint.
client.create_backend("my_backend", Counter)
client.create_endpoint("my_endpoint", backend="my_backend", route="/counter")
# Query our endpoint in two different ways: from HTTP and from Python.
print(requests.get("http://127.0.0.1:8000/counter").json())
# > {"current_counter": 1}
# > {"count": 1}
print(ray.get(client.get_handle("my_endpoint").remote()))
# > {"count": 2}
@@ -2,16 +2,20 @@ import ray
from ray import serve
import requests
ray.init(num_cpus=8)
ray.init()
client = serve.start()
def echo(starlette_request):
return "hello " + starlette_request.query_params.get("name", "serve!")
def say_hello(request):
return "hello " + request.query_params["name"] + "!"
client.create_backend("hello", echo)
client.create_endpoint("hello", backend="hello", route="/hello")
# Form a backend from our function and connect it to an endpoint.
client.create_backend("my_backend", say_hello)
client.create_endpoint("my_endpoint", backend="my_backend", route="/hello")
print(requests.get("http://127.0.0.1:8000/hello").text)
# Query our endpoint in two different ways: from HTTP and from Python.
print(requests.get("http://127.0.0.1:8000/hello?name=serve").text)
# > hello serve!
print(ray.get(client.get_handle("my_endpoint").remote(name="serve")))
# > hello serve!