-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PlainTextResponse in FastAPI/Starlette examples and tests
This sets the content type properly.
- Loading branch information
Showing
6 changed files
with
18 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from asphalt.core import Component, Context, inject, resource | ||
from fastapi import FastAPI, Response | ||
from fastapi import FastAPI | ||
from fastapi.responses import PlainTextResponse | ||
|
||
|
||
async def root() -> Response: | ||
return Response("Hello, world!") | ||
async def root() -> str: | ||
return "Hello, world!" | ||
|
||
|
||
class WebRootComponent(Component): | ||
@inject | ||
async def start(self, ctx: Context, app: FastAPI = resource()) -> None: | ||
app.add_api_route("/", root) | ||
app.add_api_route("/", root, response_class=PlainTextResponse) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from fastapi import FastAPI, Response | ||
from fastapi import FastAPI | ||
from fastapi.responses import PlainTextResponse | ||
|
||
application = FastAPI() | ||
|
||
|
||
@application.get("/") | ||
async def root() -> Response: | ||
return Response("Hello, world!") | ||
@application.get("/", response_class=PlainTextResponse) | ||
async def root() -> str: | ||
return "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from starlette.applications import Starlette | ||
from starlette.requests import Request | ||
from starlette.responses import Response | ||
from starlette.responses import PlainTextResponse, Response | ||
|
||
application = Starlette() | ||
|
||
|
||
@application.route("/") | ||
async def root(request: Request) -> Response: | ||
return Response("Hello, world!") | ||
return PlainTextResponse("Hello, world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters