✨ Add support for Response parameters to set headers, cookies, and status codes (#294)

* ✨ Add support for declaring a Response parameter to set headers and cookies

* ✅ Add source for docs and tests

* 📝 Add docs for setting headers, cookies and status code

* 📝 Add attribution to Hug for inspiring response parameters
This commit is contained in:
Sebastián Ramírez authored and GitHub committed 2019-06-06 14:29:40 +04:00
1 parent c8eea09664
commit 5f7fe926ab
17 files changed
+229 -13

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,15 @@
from starlette.testclient import TestClient
from response_change_status_code.tutorial001 import app
client = TestClient(app)
def test_path_operation():
response = client.put("/get-or-create-task/foo")
print(response.content)
assert response.status_code == 200
assert response.json() == "Listen to the Bar Fighters"
response = client.put("/get-or-create-task/bar")
assert response.status_code == 201
assert response.json() == "This didn't exist before"
@@ -0,0 +1,12 @@
from starlette.testclient import TestClient
from response_cookies.tutorial002 import app
client = TestClient(app)
def test_path_operation():
response = client.post("/cookie-and-object/")
assert response.status_code == 200
assert response.json() == {"message": "Come to the dark side, we have cookies"}
assert response.cookies["fakesession"] == "fake-cookie-session-value"
@@ -0,0 +1,12 @@
from starlette.testclient import TestClient
from response_headers.tutorial002 import app
client = TestClient(app)
def test_path_operation():
response = client.get("/headers-and-object/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
assert response.headers["X-Cat-Dog"] == "alone in the world"