Metadata-Version: 2.1
Name: classic-http-api
Version: 2.1.0
Summary: Provides wrapper around Falcon web framework, adding class-app-layer support
Home-page: https://github.com/variasov/classic-http-api
Author: Sergei Variasov
Author-email: variasov@gmail.com
Project-URL: Bug Tracker, https://github.com/variasov/classic-http-api/issues
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: falcon~=3.1
Requires-Dist: classic-components~=1.2
Requires-Dist: classic-error-handling~=0.1
Requires-Dist: msgspec~=0.18
Requires-Dist: defspec~=0.1
Provides-Extra: dev
Requires-Dist: pytest~=7.4.4; extra == "dev"
Requires-Dist: pytest-cov~=4.1; extra == "dev"
Requires-Dist: twine~=4.0; extra == "dev"
Requires-Dist: build~=1.0; extra == "dev"

# Classic HTTP Api

Этот пакет содержит вариант HTTP API, совместимый с принципами Ioc и DI.
Является оберткой над фреймворком
[Falcon](https://falcon.readthedocs.io/en/stable/index.html), 
позволяющей описывать входные и выходные параметр входных точек с помощью
[msgspec][https://jcristharif.com/msgspec/index.html], и предстоявлящей 
интеграцию с OpenAPI и Swagger.

Пример:

```python
from falcon import Request, Response
from classic.components import component
from classic.http_api import App, specification
import msgspec


# Описывает параметры запроса для GET /api/some_obj
class SomeObjFilter(msgspec.Struct):
    number: int


# Описывает структуру ответа
class SomeObj(msgspec.Struct):
    some_attr: int


# Описывает структуру запроса для POST /api/some_obj
class CreateSomeObjRequest(msgspec.Struct):
    some_attr: int


@component
class SomeObjResource:

    @specification(query=SomeObjFilter, response=SomeObj)
    def on_get(self, request: Request, response: Response):
        # Представим себе, что объекты берутся из БД
        response.media = [
            SomeObj(number)
            for number in range(
                # Объект запроса содержится в контексте под именем media.
                request.context.media.number,
            )
        ]

    @specification(media=CreateSomeObjRequest, response=SomeObj)
    def on_post(self, request: Request, response: Response):
        # Представим себе, что объект был сохранен в БД;)
        response.media = SomeObj(
            **msgspec.structs.asdict(request.context.media)
        )


# Композит
if __name__ == '__main__':
    from wsgiref.simple_server import make_server

    app = App(openapi=True)
    app.add_route('/api/some_obj', SomeObjResource())

    # 
    with make_server('', 8000, app) as httpd:
        httpd.serve_forever()

```
