mirror of
https://github.com/wassname/ray.git
synced 2026-07-11 23:25:29 +08:00
Serve Doc: Quickstart (#7940)
This commit is contained in:
+17
-1
@@ -18,11 +18,27 @@ py_test(
|
||||
deps = [":serve_lib"],
|
||||
)
|
||||
|
||||
# Make sure the example showing in doc is tested
|
||||
py_test(
|
||||
name = "echo_full",
|
||||
size = "small",
|
||||
srcs = glob(["examples/*.py"]),
|
||||
tags = ["exclusive"],
|
||||
deps = [":serve_lib"]
|
||||
)
|
||||
|
||||
# Make sure the example showing in doc is tested
|
||||
py_test(
|
||||
name = "quickstart_class",
|
||||
size = "small",
|
||||
srcs = glob(["examples/doc/*.py"]),
|
||||
tags = ["exclusive"],
|
||||
deps = [":serve_lib"]
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "quickstart_function",
|
||||
size = "small",
|
||||
srcs = glob(["examples/doc/*.py"]),
|
||||
tags = ["exclusive"],
|
||||
deps = [":serve_lib"]
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
from ray import serve
|
||||
import requests
|
||||
|
||||
serve.init()
|
||||
|
||||
|
||||
@serve.route("/counter")
|
||||
class Counter:
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
|
||||
def __call__(self, flask_request):
|
||||
return {"current_counter": self.count}
|
||||
|
||||
|
||||
requests.get("http://127.0.0.1:8000/counter").json()
|
||||
# > {"current_counter": self.count}
|
||||
@@ -0,0 +1,13 @@
|
||||
from ray import serve
|
||||
import requests
|
||||
|
||||
serve.init()
|
||||
|
||||
|
||||
@serve.route("/hello")
|
||||
def echo(flask_request):
|
||||
return "hello " + flask_request.args.get("name", "serve!")
|
||||
|
||||
|
||||
requests.get("http://127.0.0.1:8000/hello").text
|
||||
# > "hello serve!"
|
||||
Reference in New Issue
Block a user