mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-10 12:28:27 +00:00
docs(dev): new routes go in a register_<group>_routes module (#1622)
Nothing in the developer docs says where a new route goes, so the next contributor adds it to `main.py` again. This writes down the convention from Discussion #1536: a new route group gets its own `register_<group>_routes` module under `shelfmark/core/`, and `main.py` calls it once. It is one paragraph on a new page, `docs/dev/routes.md`, with a line in the developer index. It also says that a few older routes are still in `main.py` and are being moved out one group at a time. The route moves in that discussion will follow what this says, so this goes first.
This commit is contained in:
1 parent
9bd6c51388
commit
0a7e114681
2 files changed
+4
No files matched your search
@@ -4,4 +4,5 @@ Guides for adding to Shelfmark.
|
||||
|
||||
- [Release Sources Plugin Guide](release-sources-plugin-guide.md): add a source that searches for releases and a handler that downloads them
|
||||
- [Plugin Settings Guide](plugin-settings.md): add settings tabs and fields for a plugin to the Settings UI
|
||||
- [Adding Routes](routes.md): where a new API route goes, and how a route module gets what it needs
|
||||
- [Metadata Providers](../../shelfmark/metadata_providers/README.md): add a metadata provider
|
||||
@@ -0,0 +1,3 @@
|
||||
# Adding Routes
|
||||
|
||||
New API routes go in their own module under `shelfmark/core/`, named for the group (`stats_routes.py`, `settings_routes.py`), as a `register_<group>_routes(app, ...)` function that `main.py` calls once. Anything the routes need that lives in `main.py` or is shared with another group, such as `login_required`, the auth mode or the user database, is passed in as a parameter, so a route module never imports `main`. When a test patches one of those, pass a callable that is evaluated per request, the way `register_stats_routes` does. Helpers that belong to one group stay in its module. Please don't add `@app.route` handlers to `main.py` itself: two PRs that each add a route there land in the same stretch of the file and conflict, where two route modules only share the one register call. `shelfmark/core/stats_routes.py` is the smallest example to copy. A few older routes are still in `main.py` and are being moved out one group at a time, see [Discussion #1536](https://github.com/calibrain/shelfmark/discussions/1536).
|
||||
Reference in new issue
Block a user