Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier to learn README.md #23

Merged
merged 17 commits into from
Jan 31, 2021
Prev Previous commit
Next Next commit
README.md:add:example 3:ready
  • Loading branch information
OmarThinks committed Jan 30, 2021
commit b270923c7b86b1760978c936e37f59883111ca49
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def post(body:RequestBodyModel): # expected request body
# received, validated and sanitized from the request body

# save model to DB
id = 1
age = 2 # we should have got them from db
id = 0
age = 1000 # we should have got them from db

return ResponseModel(
id=id, age=age, name=name, nickname=nickname
Expand All @@ -100,9 +100,33 @@ def get(query:QueryModel):
# received and sanitized from the query paramters

# save model to DB
id = 1 # we should have got it from db
id = 0 # we should have got it from db
name = "abc"
nickname = "123"
return ResponseModel(
id=id, age=age, name=name, nickname=nickname
)

"""
Example 3:
receive inputs from BOTH:
1) request_body
2) query paramaters
In the same request
"""
@app.route("/both", methods=["POST"])
@validate()
def get_and_post(body:RequestBodyModel,query:QueryModel):
# From request body
name = body.name
nickname = body.nickname

# from query parameters
age = query.age

# save model to DB
id = 0 # we should have got it from db

return ResponseModel(
id=id, age=age, name=name, nickname=nickname,
)
Expand Down