macss-modular-api 0.4.6__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/LICENSE +9 -9
  2. {macss_modular_api-0.4.6/src/macss_modular_api.egg-info → macss_modular_api-0.5.0}/PKG-INFO +212 -148
  3. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/README.md +172 -113
  4. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/pyproject.toml +59 -55
  5. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/setup.cfg +4 -4
  6. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0/src/macss_modular_api.egg-info}/PKG-INFO +212 -148
  7. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/macss_modular_api.egg-info/SOURCES.txt +23 -0
  8. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/macss_modular_api.egg-info/requires.txt +6 -0
  9. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/__init__.py +111 -72
  10. macss_modular_api-0.5.0/src/modular_api/core/error_response_middleware.py +33 -0
  11. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/health/health_check.py +84 -84
  12. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/health/health_handler.py +30 -30
  13. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/health/health_service.py +113 -113
  14. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/logger/logger.py +183 -181
  15. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/logger/logging_middleware.py +130 -120
  16. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/metrics/metric.py +294 -294
  17. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/metrics/metric_registry.py +208 -208
  18. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/metrics/metrics_middleware.py +111 -111
  19. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/modular_api.py +281 -215
  20. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/module_builder.py +182 -182
  21. macss_modular_api-0.5.0/src/modular_api/core/official_plugins.py +346 -0
  22. macss_modular_api-0.5.0/src/modular_api/core/plugin.py +590 -0
  23. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/registry.py +65 -65
  24. macss_modular_api-0.5.0/src/modular_api/core/request_pipeline_audit.py +38 -0
  25. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/use_case_exception.py +51 -51
  26. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/usecase.py +202 -202
  27. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/usecase_handler.py +144 -144
  28. macss_modular_api-0.5.0/src/modular_api/graphql/__init__.py +135 -0
  29. macss_modular_api-0.5.0/src/modular_api/graphql/catalog/__init__.py +49 -0
  30. macss_modular_api-0.5.0/src/modular_api/graphql/catalog/graphql_catalog_builder.py +792 -0
  31. macss_modular_api-0.5.0/src/modular_api/graphql/metadata/__init__.py +25 -0
  32. macss_modular_api-0.5.0/src/modular_api/graphql/metadata/graphql_metadata_parser.py +503 -0
  33. macss_modular_api-0.5.0/src/modular_api/graphql/read/__init__.py +49 -0
  34. macss_modular_api-0.5.0/src/modular_api/graphql/read/sql_read_contract.py +157 -0
  35. macss_modular_api-0.5.0/src/modular_api/graphql/read/sqlserver_read_compiler.py +384 -0
  36. macss_modular_api-0.5.0/src/modular_api/graphql/runtime/__init__.py +33 -0
  37. macss_modular_api-0.5.0/src/modular_api/graphql/runtime/graphql_artifacts.py +589 -0
  38. macss_modular_api-0.5.0/src/modular_api/graphql/runtime/graphql_runtime_options.py +60 -0
  39. macss_modular_api-0.5.0/src/modular_api/graphql/runtime/graphql_runtime_plugin.py +1113 -0
  40. macss_modular_api-0.5.0/src/modular_api/graphql/schema/__init__.py +5 -0
  41. macss_modular_api-0.5.0/src/modular_api/graphql/schema/graphql_schema_sdl_generator.py +219 -0
  42. macss_modular_api-0.5.0/src/modular_api/graphql/sqlserver/__init__.py +25 -0
  43. macss_modular_api-0.5.0/src/modular_api/graphql/sqlserver/physical_model.py +43 -0
  44. macss_modular_api-0.5.0/src/modular_api/graphql/sqlserver/sql_server_connection_settings.py +48 -0
  45. macss_modular_api-0.5.0/src/modular_api/graphql/sqlserver/sql_server_metadata_reader.py +393 -0
  46. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/middlewares/cors.py +78 -78
  47. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/openapi/openapi.py +256 -256
  48. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/openapi/swagger_docs.py +52 -48
  49. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_auto_schema.py +116 -116
  50. macss_modular_api-0.5.0/tests/test_clean_room_driver_isolation.py +40 -0
  51. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_field_example.py +90 -90
  52. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_fromjson_validation.py +148 -148
  53. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_modular_api.py +283 -283
  54. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_module_builder.py +87 -87
  55. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_schema_conformance.py +68 -68
  56. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_use_case_exception.py +82 -82
  57. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_usecase.py +124 -124
  58. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/tests/test_usecase_handler.py +284 -284
  59. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/macss_modular_api.egg-info/dependency_links.txt +0 -0
  60. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/macss_modular_api.egg-info/top_level.txt +0 -0
  61. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/__init__.py +0 -0
  62. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/health/__init__.py +0 -0
  63. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/logger/__init__.py +0 -0
  64. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/core/metrics/__init__.py +0 -0
  65. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/middlewares/__init__.py +0 -0
  66. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/openapi/__init__.py +0 -0
  67. {macss_modular_api-0.4.6 → macss_modular_api-0.5.0}/src/modular_api/py.typed +0 -0
@@ -1,9 +1,9 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 @ccisnedev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 @ccisnedev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,148 +1,212 @@
1
- Metadata-Version: 2.4
2
- Name: macss-modular-api
3
- Version: 0.4.6
4
- Summary: Use-case-centric toolkit for building modular APIs with Starlette. Define UseCase classes (input → validate → execute → output), connect them to HTTP routes, and expose OpenAPI documentation automatically.
5
- Author: ccisne.dev
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/macss-dev/modular_api
8
- Project-URL: Repository, https://github.com/macss-dev/modular_api/tree/main/code/py
9
- Project-URL: Issues, https://github.com/macss-dev/modular_api/issues
10
- Project-URL: Documentation, https://github.com/macss-dev/modular_api/tree/main/code/py#readme
11
- Keywords: api,usecase,openapi,starlette,modular,macss
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Framework :: AsyncIO
14
- Classifier: Intended Audience :: Developers
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
20
- Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
- Classifier: Typing :: Typed
22
- Requires-Python: >=3.11
23
- Description-Content-Type: text/markdown
24
- License-File: LICENSE
25
- Requires-Dist: starlette>=0.40
26
- Requires-Dist: pydantic>=2.0
27
- Provides-Extra: serve
28
- Requires-Dist: uvicorn>=0.30; extra == "serve"
29
- Provides-Extra: dev
30
- Requires-Dist: pytest>=8.0; extra == "dev"
31
- Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
32
- Requires-Dist: httpx>=0.27; extra == "dev"
33
- Requires-Dist: uvicorn>=0.30; extra == "dev"
34
- Dynamic: license-file
35
-
36
- # modular-api
37
-
38
- Use-case-centric toolkit for building modular APIs with Starlette.
39
- Define `UseCase` classes (input → validate → execute → output), connect them to HTTP routes, and get automatic OpenAPI documentation.
40
-
41
- > Also available in **Dart**: [modular_api](https://pub.dev/packages/modular_api) · **TypeScript**: [@macss/modular-api](https://www.npmjs.com/package/@macss/modular-api)
42
-
43
- ---
44
-
45
- ## Quick start
46
-
47
- ```python
48
- from modular_api import ModularApi, ModuleBuilder
49
-
50
- # ─── Module builder (separate file in real projects) ──────────
51
- def build_greetings_module(m: ModuleBuilder) -> None:
52
- m.usecase("hello", HelloWorld)
53
-
54
- # ─── Server ───────────────────────────────────────────────────
55
- api = ModularApi(base_path="/api")
56
-
57
- api.module("greetings", build_greetings_module)
58
-
59
- api.serve(port=8080)
60
- ```
61
-
62
- ```bash
63
- curl -X POST http://localhost:8080/api/greetings/hello \
64
- -H "Content-Type: application/json" \
65
- -d '{"name":"World"}'
66
- ```
67
-
68
- ```json
69
- { "message": "Hello, World!" }
70
- ```
71
-
72
- **Docs** → `http://localhost:8080/docs`
73
- **Health** → `http://localhost:8080/health`
74
- **OpenAPI JSON** → `http://localhost:8080/openapi.json` *(also /openapi.yaml)*
75
- **Metrics** → `http://localhost:8080/metrics` *(opt-in)*
76
-
77
- See `example/example.py` for the full implementation including Input, Output, UseCase with `validate()`, and the builder.
78
-
79
- ---
80
-
81
- ## Features
82
-
83
- - `UseCase[I, O]` — pure business logic, no HTTP concerns
84
- - `Input` / `Output` — DTOs with automatic OpenAPI schema generation via Pydantic `Field()`
85
- - `Output.status_code` — custom HTTP status codes per response
86
- - `UseCaseException` — structured error handling (status_code, message, error_code, details)
87
- - `ModularApi` + `ModuleBuilder` — module registration and routing
88
- - Constructor-based unit testing with fake dependency injection
89
- - `cors_middleware` — built-in CORS support
90
- - Scalar docs at `/docs` — auto-generated from registered use cases
91
- - OpenAPI spec at `/openapi.json` and `/openapi.yaml` — raw spec download
92
- - Health check at `GET /health` — [IETF Health Check Response Format](doc/health_check_guide.md)
93
- - Prometheus metrics at `GET /metrics` — [Prometheus exposition format](doc/metrics_guide.md)
94
- - Structured JSON logging — Loki/Grafana compatible, [request-scoped with trace_id](doc/logger_guide.md)
95
- - All endpoints default to `POST` (configurable per use case)
96
- - Full type annotations with `py.typed` marker (PEP 561)
97
-
98
- ---
99
-
100
- ## Installation
101
-
102
- ```bash
103
- pip install modular-api
104
- ```
105
-
106
- With Uvicorn for `api.serve()`:
107
-
108
- ```bash
109
- pip install modular-api[serve]
110
- ```
111
-
112
- ---
113
-
114
- ## Error handling
115
-
116
- ```python
117
- async def execute(self) -> FoundUserOutput:
118
- user = await repository.find_by_id(self.input.user_id)
119
- if not user:
120
- raise UseCaseException(
121
- status_code=404,
122
- message="User not found",
123
- error_code="USER_NOT_FOUND",
124
- )
125
- return FoundUserOutput(name=user.name)
126
- ```
127
-
128
- ---
129
-
130
- ## Testing
131
-
132
- ```python
133
- async def test_hello_world():
134
- usecase = HelloWorld(HelloInput(name="World"))
135
- error = usecase.validate()
136
- assert error is None
137
-
138
- output = await usecase.execute()
139
- assert output.message == "Hello, World!"
140
- ```
141
-
142
- See [doc/testing_guide.md](doc/testing_guide.md) for the full testing guide.
143
-
144
- ---
145
-
146
- ## License
147
-
148
- MIT — see [LICENSE](LICENSE).
1
+ Metadata-Version: 2.4
2
+ Name: macss-modular-api
3
+ Version: 0.5.0
4
+ Summary: Use-case-centric toolkit for building modular APIs with Starlette. Define UseCase classes (input → validate → execute → output), connect them to HTTP routes, and expose OpenAPI documentation automatically.
5
+ Author: ccisne.dev
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/macss-dev/modular_api
8
+ Project-URL: Repository, https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api
9
+ Project-URL: Issues, https://github.com/macss-dev/modular_api/issues
10
+ Project-URL: Documentation, https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api#readme
11
+ Keywords: api,usecase,openapi,starlette,modular,macss
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
20
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: starlette>=0.40
26
+ Requires-Dist: pydantic>=2.0
27
+ Provides-Extra: serve
28
+ Requires-Dist: uvicorn>=0.30; extra == "serve"
29
+ Provides-Extra: graphql
30
+ Requires-Dist: json5>=0.9.14; extra == "graphql"
31
+ Requires-Dist: graphql-core<3.3,>=3.2; extra == "graphql"
32
+ Provides-Extra: dev
33
+ Requires-Dist: json5>=0.9.14; extra == "dev"
34
+ Requires-Dist: graphql-core<3.3,>=3.2; extra == "dev"
35
+ Requires-Dist: pytest>=8.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
37
+ Requires-Dist: httpx>=0.27; extra == "dev"
38
+ Requires-Dist: uvicorn>=0.30; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # modular-api
42
+
43
+ Use-case-centric toolkit for building modular APIs with Starlette.
44
+ Define `UseCase` classes (input → validate → execute → output), connect them to HTTP routes, and get automatic OpenAPI documentation.
45
+
46
+ > Also available in **Dart**: [modular_api](https://pub.dev/packages/modular_api) · **TypeScript**: [@macss/modular-api](https://www.npmjs.com/package/@macss/modular-api)
47
+
48
+ ---
49
+
50
+ ## Quick start
51
+
52
+ ```python
53
+ from modular_api import ModularApi, ModuleBuilder
54
+
55
+ # ─── Module builder (separate file in real projects) ──────────
56
+ def build_greetings_module(m: ModuleBuilder) -> None:
57
+ m.usecase("hello", HelloWorld)
58
+
59
+ # ─── Server ───────────────────────────────────────────────────
60
+ api = ModularApi(base_path="/api")
61
+
62
+ api.module("greetings", build_greetings_module)
63
+
64
+ api.serve(port=8080)
65
+ ```
66
+
67
+ ```bash
68
+ curl -X POST http://localhost:8080/api/greetings/hello \
69
+ -H "Content-Type: application/json" \
70
+ -d '{"name":"World"}'
71
+ ```
72
+
73
+ ```json
74
+ { "message": "Hello, World!" }
75
+ ```
76
+
77
+ **Docs** → `http://localhost:8080/api/docs`
78
+ **Health** → `http://localhost:8080/api/health`
79
+ **OpenAPI JSON** → `http://localhost:8080/api/openapi.json` *(also /api/openapi.yaml)*
80
+ **Metrics** → `http://localhost:8080/api/metrics` *(opt-in)*
81
+
82
+ See `example/example.py` for the full implementation including Input, Output, UseCase with `validate()`, and the builder.
83
+
84
+ ---
85
+
86
+ ## Features
87
+
88
+ - `UseCase[I, O]` — pure business logic, no HTTP concerns
89
+ - `Input` / `Output` — DTOs with automatic OpenAPI schema generation via Pydantic `Field()`
90
+ - `Output.status_code` — custom HTTP status codes per response
91
+ - `UseCaseException` — structured error handling (status_code, message, error_code, details)
92
+ - `ModularApi` + `ModuleBuilder` — module registration and routing
93
+ - Constructor-based unit testing with fake dependency injection
94
+ - `cors_middleware` — built-in CORS support
95
+ - All public endpoints resolve under the configured `base_path`.
96
+ - Swagger UI at `/{basePath}/docs` — auto-generated from registered use cases
97
+ - OpenAPI spec at `/{basePath}/openapi.json` and `/{basePath}/openapi.yaml` — raw spec download
98
+ - Health check at `GET /{basePath}/health` — [IETF Health Check Response Format](doc/health_check_guide.md)
99
+ - Prometheus metrics at `GET /{basePath}/metrics` — [Prometheus exposition format](doc/metrics_guide.md)
100
+ - Structured JSON logging — Loki/Grafana compatible, [request-scoped with trace_id](doc/logger_guide.md)
101
+ - All endpoints default to `POST` (configurable per use case)
102
+ - Full type annotations with `py.typed` marker (PEP 561)
103
+
104
+ ---
105
+
106
+ ## Plugin host
107
+
108
+ The public plugin contract is available from the package exports and is already
109
+ used by the official health, metrics, OpenAPI, and docs plugins.
110
+
111
+ Current lifecycle behavior:
112
+
113
+ - `api.plugin(...)` registers a plugin instance without running setup yet
114
+ - `setup(host)` runs during `build()` in dependency order
115
+ - `validate(host)` runs after registration freeze and can abort startup
116
+ - `shutdown()` runs in reverse setup order on normal shutdown and on partial
117
+ startup rollback
118
+ - plugin routes always resolve under the configured `base_path`
119
+ - all three public middleware slots are active with deterministic ordering
120
+
121
+ ```python
122
+ from modular_api import ModularApi, Plugin, PluginHost, PluginManifest, PluginRoute
123
+
124
+
125
+ class HelloPlugin(Plugin):
126
+ manifest = PluginManifest(
127
+ id="acme.hello",
128
+ display_name="Hello Plugin",
129
+ version="0.1.0",
130
+ host_api_version=">=0.1.0 <0.2.0",
131
+ )
132
+
133
+ def setup(self, host: PluginHost) -> None:
134
+ host.register_route(
135
+ PluginRoute(
136
+ id="hello-plugin",
137
+ method="GET",
138
+ path="/hello-plugin",
139
+ visibility="custom",
140
+ # Optional OpenAPI Operation object — when present, the official
141
+ # OpenApiPlugin merges the route into /openapi.json and /docs (ADR-0003).
142
+ openapi={
143
+ "summary": "Hello from a plugin route",
144
+ "responses": {"200": {"description": "OK"}},
145
+ },
146
+ handler=lambda _: {
147
+ "status": 200,
148
+ "body": {"ok": True, "basePath": host.metadata().base_path},
149
+ },
150
+ )
151
+ )
152
+
153
+ def validate(self, host: PluginHost):
154
+ return []
155
+
156
+
157
+ api = ModularApi(base_path="/api")
158
+ api.plugin(HelloPlugin())
159
+ app = api.build()
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Installation
165
+
166
+ ```bash
167
+ pip install macss-modular-api
168
+ ```
169
+
170
+ With Uvicorn for `api.serve()`:
171
+
172
+ ```bash
173
+ pip install macss-modular-api[serve]
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Error handling
179
+
180
+ ```python
181
+ async def execute(self) -> FoundUserOutput:
182
+ user = await repository.find_by_id(self.input.user_id)
183
+ if not user:
184
+ raise UseCaseException(
185
+ status_code=404,
186
+ message="User not found",
187
+ error_code="USER_NOT_FOUND",
188
+ )
189
+ return FoundUserOutput(name=user.name)
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Testing
195
+
196
+ ```python
197
+ async def test_hello_world():
198
+ usecase = HelloWorld(HelloInput(name="World"))
199
+ error = usecase.validate()
200
+ assert error is None
201
+
202
+ output = await usecase.execute()
203
+ assert output.message == "Hello, World!"
204
+ ```
205
+
206
+ See [doc/testing_guide.md](doc/testing_guide.md) for the full testing guide.
207
+
208
+ ---
209
+
210
+ ## License
211
+
212
+ MIT — see [LICENSE](LICENSE).