Skip to content

Declare post data type and response data type #158

@lea108

Description

@lea108

Problem to Solve

When reading endpoints code it is sometimes complicated to infer the non-path parameters it accepts or the data type it returns.

Both for humans and for tooling.

Proposal

Make it possible to declare a datatype for the POST body and the response data. Possible with an encoder/decoder to describe if it is encoded as json, xml, msgpack etc.

Inspiration may be drawn from FastAPI that does this using decorators in combination with method parameters:

@app.post("/items/", response_model=Item)
async def create_item(item: Item):
    return item

Use Case

Especially in teams of multiple people, make it easier to read what the actual interface is of different APIs.

May also be the foundation of automatic OpenAPI docs generation, similar to how FastAPI does it.

Alternatives

For post body, to imperatively read payload data in the beginning of the endpoint handler. And declare the datatype in the function comment.

For response model to declare it in the function comment.

Additional context

No response

How experienced are you with this library?

Beginner - Just getting started with this library

Are you interested in working on a PR for this?

  • I want to work on this

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog 🗂️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions