From f26f26957b5ca99ccf1531497be5347ef559f37f Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Mon, 7 Jun 2021 21:41:54 -0700 Subject: [PATCH] Update examples (#2234) (cherry picked from commit 2f3caa455cdc32a23de1185b07022f0378f3fd97) --- docs/workloads/async/example.md | 16 ++++++++++------ docs/workloads/batch/example.md | 9 +++++---- docs/workloads/realtime/example.md | 19 ++++++++++++------- docs/workloads/task/example.md | 4 ++-- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/docs/workloads/async/example.md b/docs/workloads/async/example.md index 650b8bb5c2..a362b66477 100644 --- a/docs/workloads/async/example.md +++ b/docs/workloads/async/example.md @@ -6,12 +6,16 @@ # main.py from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() +class Data(BaseModel): + msg: str + @app.post("/") -def hello_world(): - return {"msg": "hello world"} +def handle_async(data: Data): + return data ``` ### Create a `Dockerfile` @@ -28,19 +32,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app ### Build an image ```bash -docker build . --tag hello-world +docker build . -t hello-world ``` ### Run a container locally ```bash -docker run --port 8080:8080 hello-world +docker run -p 8080:8080 hello-world ``` ### Make a request ```bash -curl --request POST --header "Content-Type: application/json" localhost:8080 +curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' localhost:8080 ``` ### Login to ECR @@ -101,7 +105,7 @@ cortex get hello-world ### Make a request ```bash -curl --request POST --header "Content-Type: application/json" http://***.amazonaws.com/hello-world +curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' http://***.amazonaws.com/hello-world ``` ### Get the response diff --git a/docs/workloads/batch/example.md b/docs/workloads/batch/example.md index e6743c4565..eca6248390 100644 --- a/docs/workloads/batch/example.md +++ b/docs/workloads/batch/example.md @@ -25,6 +25,7 @@ def on_job_complete(): FROM python:3.8-slim RUN pip install --no-cache-dir fastapi uvicorn + COPY main.py / CMD uvicorn --host 0.0.0.0 --port 8080 main:app @@ -33,19 +34,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app ### Build an image ```bash -docker build . --tag hello-world +docker build . -t hello-world ``` ### Run a container locally ```bash -docker run --port 8080:8080 hello-world +docker run -p 8080:8080 hello-world ``` ### Make a request ```bash -curl --request POST --header "Content-Type: application/json" --data '[1,2,3,4]' localhost:8080 +curl -X POST -H "Content-Type: application/json" -d '[1,2,3,4]' localhost:8080 ``` ### Login to ECR @@ -101,7 +102,7 @@ cortex get hello-world ### Make a request ```bash -curl --request POST --header "Content-Type: application/json" --data '{"workers": 2, "item_list": {"items": [1,2,3,4], "batch_size": 2}}' http://***.amazonaws.com/hello-world +curl -X POST -H "Content-Type: application/json" -d '{"workers": 2, "item_list": {"items": [1,2,3,4], "batch_size": 2}}' http://***.amazonaws.com/hello-world ``` ### View the logs diff --git a/docs/workloads/realtime/example.md b/docs/workloads/realtime/example.md index 2698269ed4..aa68e98d5d 100644 --- a/docs/workloads/realtime/example.md +++ b/docs/workloads/realtime/example.md @@ -6,12 +6,16 @@ # main.py from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() -@app.get("/") -def hello_world(): - return {"msg": "hello world"} +class Data(BaseModel): + msg: str + +@app.post("/") +def handle_post(data: Data): + return data ``` ### Create a `Dockerfile` @@ -20,6 +24,7 @@ def hello_world(): FROM python:3.8-slim RUN pip install --no-cache-dir fastapi uvicorn + COPY main.py / CMD uvicorn --host 0.0.0.0 --port 8080 main:app @@ -28,19 +33,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app ### Build an image ```bash -docker build . --tag hello-world +docker build . -t hello-world ``` ### Run a container locally ```bash -docker run --port 8080:8080 hello-world +docker run -p 8080:8080 hello-world ``` ### Make a request ```bash -curl --request POST localhost:8080 +curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' localhost:8080 ``` ### Login to ECR @@ -101,5 +106,5 @@ cortex get hello-world ### Make a request ```bash -curl --request POST http://***.amazonaws.com/hello-world +curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' http://***.amazonaws.com/hello-world ``` diff --git a/docs/workloads/task/example.md b/docs/workloads/task/example.md index 92f53b2938..423164cbdb 100644 --- a/docs/workloads/task/example.md +++ b/docs/workloads/task/example.md @@ -21,7 +21,7 @@ CMD exec python main.py ### Build an image ```bash -docker build . --tag hello-world +docker build . -t hello-world ``` ### Run a container locally @@ -83,7 +83,7 @@ cortex get hello-world ### Make a request ```bash -curl --request POST --header "Content-Type: application/json" --data '{}' http://***.amazonaws.com/hello-world +curl -X POST -H "Content-Type: application/json" -d '{}' http://***.amazonaws.com/hello-world ``` ### View the logs