-
|
Is it possible to process requests directly using Starlette without using a routing table and if so, how? For instance (in Go), it's possible to handle a request directly with a Handler and then perform path based routing manually: func ManualRouteHandler(w http.ResponseWriter, req *http.Request) {
cleanPath := path.Clean(req.URL.Path)
if strings.HasPrefix(cleanPath, "/api") {
// if the the path starts with /api, use the apiHandler
// pass down the response and request to the next handler
apiHandler.ServeHTTP(w, req)
return
} else {
// if it's any other path, use the fileHandler
// pass down the response and request to the next handler
fileHandler.ServeHTTP(w, req)
return
}
}Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
adriangb
Mar 28, 2023
Replies: 1 comment
-
|
Yes and no: you can easily create a catchall handler ( async def app(scope, receive, send):
request = Request(scope, receive)
... |
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
Yes and no: you can easily create a catchall handler (
"/{rest_of_path:path}"or/foo/{rest_of_path:path}) and handle routing in there. But there is a still a routing table running. If you want no routing table whatsoever you can crate a pure ASIG app and use Starlette as a toolkit: