11# Mounting applications
22
3- The word " mounting" refers to the ability to plug ASGI applications into
4- others, under specific routes. This enables reusing whole applications, or
5- components, across web applications. This page describes :
3+ The term ' mounting' refers to the ability to integrate ASGI applications into others
4+ under specific routes. This enables reusing whole applications across web applications.
5+ This page covers :
66
7- - [X] How to use the mount feature in BlackSheep .
8- - [X] Details about mounting, and handling of application events.
7+ - [X] Using the mount feature.
8+ - [X] Details about mounting and handling of application events.
99- [X] Mounting and OpenAPI Documentation.
1010- [X] An example using [ Piccolo Admin] ( https://github.com/piccolo-orm/piccolo_admin ) .
1111
@@ -50,18 +50,18 @@ In the example above, both `parent` and `child` are complete applications that
5050can be started independently. If ` child ` is started alone, it replies to GET
5151web requests at route "/" with the text "Hello, from the child app".
5252
53- Since ` parent ` mounts ` child ` under the path "/sub", when ` parent ` is started, it
54- delegates requests starting with ` /sub/* ` to the mounted application, therefore when the
55- ` parent ` is started, a GET request to the route "/sub" produces the greetings message
56- from ` child ` . A GET request to the route "/" instead is replied with the text "Hello,
57- from the parent app".
53+ Since ` parent ` mounts ` child ` under the path '/sub', it delegates requests starting with
54+ ` /sub/* ` to the mounted application. As a result, when parent is started, a GET request
55+ to the route '/sub' produces the greeting message from ` child ` . A GET request to the
56+ route "/" instead is replied with the text "Hello, from the parent app".
5857
59- !!! info
58+ /// !!! info
6059 Try to create a file ` server.py ` like in the example above, and run the
6160 applications using ` uvicorn ` , to verify how they work in practice.
6261
6362## Side effects of mounting
64- Even though mounting can enable interesting scenarios, it comes at a price.
63+
64+ Although mounting enables interesting scenarios, it comes at a cost.
6565
6666Applications that are supposed to be mounted by other applications need to be
6767designed to be "mount-friendly", for example when they handle redirects or
@@ -115,9 +115,9 @@ app_b.mount("/a", app_a)
115115
116116```
117117
118- This won't produce the expected result in real-life scenarios! ` app_a ` in this
118+ This won't produce the expected result in real-life scenarios. ` app_a ` in this
119119case redirects to the absolute path "/", therefore a path that is handled by
120- ` app_b ` ! In general, mounted apps will be defined in dedicated packages with
120+ ` app_b ` . In general, mounted apps will be defined in dedicated packages with
121121no knowledge of the applications that mount them. To fix this scenario, it is
122122necessary to use a relative path for redirection, like:
123123
@@ -128,6 +128,7 @@ def redirect_to_home():
128128```
129129
130130### Handling of application events
131+
131132Applications often need to define actions that must happen when the application
132133starts, and actions that must happen when the application stops.
133134
@@ -173,11 +174,8 @@ events.
173174 web framework used to implement it. The example above is correct when ` child `
174175 is an instance of BlackSheep Application.
175176
176- !!! danger "Note"
177- ` APP_MOUNT_AUTO_EVENTS ` is not the default to not introduce breaking changes.
178- This will be the default behavior in BlackSheep 2.x
179-
180177## Mounting and OpenAPI Documentation
178+
181179Since version ` 1.2.5 ` , BlackSheep supports generating OpenAPI Documentation
182180for mounted BlackSheep applications, meaning that parent applications can expose
183181OpenAPI Documentation about all endpoints, including those of mounted apps and
@@ -307,6 +305,7 @@ Produces OpenAPI Documentation for all endpoints.
307305![ Mount OAD] ( ./img/mount-oad.png )
308306
309307## Examples
308+
310309To see a working example where ` mount ` is used, see [ the Piccolo Admin example
311310at
312311_ BlackSheep-Examples_ ] ( https://github.com/Neoteroi/BlackSheep-Examples/tree/main/piccolo-admin ) .
0 commit comments