After authentication, Batman was worried about the website traffic during the rush hours. He was worried about the server crashing when Joker would try to break all the criminals from the Arkham asylum one more time. So, Robyn told him about the Const Requests
feature and the multi-core scaling potential.
Const Requests
Robyn told Batman that you can pre-compute the response for each route. This will compute the response even before execution. This will improve the response time bypassing the need to access the router.
Request
@app.get("/", const=True)
async def h():
return "Hello, world"
Muli-core scaling
Robyn told Batman that he can use the --workers
flag to scale the application to multiple cores. This will create multiple instances of the application and will distribute the load among them. This will improve the performance of the application.
Request
python3 app.py --workers=N --process=M
The authenticate method should return an Identity
object if the user is authenticated, or None
otherwise. The Identity object can contain any data you want, and will be accessible in the route methods using the request.identity
attribute.
Note: that this authentication system is basically only using a before request
middleware under the hood. This means you can overlook it and create your own authentication system using middlewares if you want to. However, Robyn still provide this easy to implement solution that should suit most use cases.
What's next?
After making the application faster, Batman was happy and wanted to make a request from his Frontend Dashboard.
But he was faced with CORS issues! He asked Robyn about how to solve this issue. Robyn told him about the following features