Serve Doc: Quickstart (#7940)

This commit is contained in:
Simon Mo
2020-04-15 12:25:37 -07:00
committed by GitHub
parent ba00c29b67
commit 7455610d5a
8 changed files with 121 additions and 25 deletions
+17 -1
View File
@@ -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!"