Components
Components
Every app has some hot objects that should be available almost everywhere. Maybe they are database instances, maybe request objects. Vibora call these objects components
For now you should pay close attention to the Request
component:
This is the most important component and will be everywhere in your app. It holds all information related to the current request and also some useful references like the current application and route.
You can ask for components in your route by using type hints:
The request object has a special method that allows you to ask for more components as you go.
By now you should have noticed that Vibora is smart enough to know which components do you want in your routes so your routes may not receive any parameters at all or ask as many components do you wish.
Adding custom components
Vibora was designed to avoid global magic (unlike Flask for example) because it makes testing harder and more prone to errors specially in async environments.
To help with this, Vibora provides an API where you can register objects to later use.
This means they are correctly encapsulated into a single app object, allowing many apps instances to work concurrently, encouraging the use of type hints which brings many benefits in the long-term and also make your routes much easier to test.
Last updated