You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/deployment/integrated.md
+9-18Lines changed: 9 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
The `optimade` package can be used to create a standalone web application that serves the OPTIMADE API based on a pre-configured MongoDB backend.
4
4
In this document, we are going to use `optimade` differently and use it to add an OPTIMADE API implementation alongside an existing API that employs an Elasticsearch storage layer.
5
5
6
-
Let's assume we already have a *FastAPI* application that runs an unrelated web service, and that we use an Elasticsearch backend that contains all structure data, but not necessarily in a form that OPTIMADE expects.
6
+
Let's assume we already have a _FastAPI_ application that runs an unrelated web service, and that we use an Elasticsearch backend that contains all structure data, but not necessarily in a form that OPTIMADE expects.
7
7
8
8
## Providing the `optimade` configuration
9
9
@@ -13,7 +13,7 @@ If you run `optimade` code inside another application, you might want to provide
13
13
Let's say you have a file `optimade_config.json` as part of the Python module that you use to create your OPTIMADE API.
14
14
15
15
!!! tip
16
-
You can find more detailed information about configuring the `optimade` server in the [Configuration](../configuration.md) section.
16
+
You can find more detailed information about configuring the `optimade` server in the [Configuration](../configuration.md) section.
17
17
18
18
Before importing any `optimade` modules, you can set the `OPTIMADE_CONFIG_FILE` environment variable to refer to your config file:
You can imagine that `MyElasticsearchStructureCollection` either sub-classes the default `optimade` Elasticsearch implementation ([`ElasticsearchCollection`][optimade.server.entry_collections.elasticsearch.ElasticCollection]) or sub-classes [`EntryCollection`][optimade.server.entry_collections.entry_collections.EntryCollection], depending on how deeply you need to customize the default `optimade` behavior.
39
39
40
-
## Mounting the OPTIMADE Python tools *FastAPI* app into an existing *FastAPI* app
40
+
## Mounting the OPTIMADE Python tools _FastAPI_ app into an existing _FastAPI_ app
41
41
42
-
Let's assume you have an existing *FastAPI* app `my_app`.
42
+
Let's assume you have an existing _FastAPI_ app `my_app`.
43
43
It already implements a few routers under certain path prefixes, and now you want to add an OPTIMADE implementation under the path prefix `/optimade`.
44
44
45
-
First, you have to set the `root_path` in the `optimade` configuration, so that the app expects all requests to be prefixed with `/optimade`.
45
+
The primary thing to modify is the `base_url` to match the new subpath. The easiest is to just update your configuration file or env parameters.
46
46
47
-
Second, you simply mount the `optimade` app into your existing app `my_app`:
47
+
Then one can just simply do the following:
48
48
49
49
```python
50
-
from optimade.server.configimportCONFIG
50
+
from optimade.server.mainimportmain as optimade
51
51
52
-
CONFIG.root_path ="/optimade"
53
-
54
-
from optimade.server import main as optimade
55
-
56
-
optimade.add_major_version_base_url(optimade.app)
57
52
my_app.mount("/optimade", optimade.app)
58
53
```
59
54
60
-
!!! tip
61
-
In the example above, we imported `CONFIG` before `main` so that our config was loaded before app creation.
62
-
To avoid the need for this, the `root_path` can be set in your JSON config file, passed as an environment variable, or declared in a custom Python module (see [Configuration](../configuration.md)).
63
-
64
-
See also the *FastAPI* documentation on [sub-applications](https://fastapi.tiangolo.com/advanced/sub-applications/).
55
+
See also the _FastAPI_ documentation on [sub-applications](https://fastapi.tiangolo.com/advanced/sub-applications/).
65
56
66
-
Now, if you run `my_app`, it will still serve all its routers as before and in addition it will also serve all OPTIMADE routes under `/optimade/` and the versioned URLs `/optimade/v1/`.
57
+
Now, if you run `my_app`, it will still serve all its routers as before and in addition it will also serve all OPTIMADE routes under `/optimade/`.
Note that `ServerConfig()` returns the configuration based on the usual sources - env variables or json file (see [Configuration](../configuration.md) section).
0 commit comments