-
|
When I checked the official demo recently, I found that this code can't start the route and the parameter is missing import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response, PlainTextResponse
from starlette.routing import Route
async def apps(scope, receive, send):
assert scope['type'] == 'http'
request = Request(scope, receive)
content = '%s %s' % (request.method, request.url.path)
response = Response(content, media_type='text/plain')
await response(scope, receive, send)
def text(request):
return PlainTextResponse('Hello')
routes = [
Route("/s/{s}", endpoint=apps),
Route("/t/{t}", endpoint=text),
]
app = Starlette(routes=routes)
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8082) error code The routing service doesn't seem to inherit receive and send, and can't go down |
Beta Was this translation helpful? Give feedback.
Answered by
jhominal
Jul 10, 2022
Replies: 1 comment
-
|
As There is more information in the documentation, in the Routing section. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Route.endpointcurrently accepts either:starlette.requests.Requestand returns astarlette.responses.Responseobject (like yourtext),__init__that implements the ASGI interface (which you can use by e.g. subclassingstarlette.endpoints.HTTPEndpoint).As
appsis not in either case, it doesn’t work withRoute.endpointas currently implemented by Starlette.There is more information in the documentation, in the Routing section.