litestar icon indicating copy to clipboard operation
litestar copied to clipboard

Docs: let's improve "DTO: basic use" page

Open sobolevn opened this issue 4 months ago • 2 comments

Summary

Right now https://docs.litestar.dev/latest/usage/dto/0-basic-use.html starts with:

Снимок экрана 2024-10-15 в 14 51 26

and I was like: wait a second!

Here we demonstrate how to declare DTO types to your route handlers. For demonstration purposes, we assume that we are working with a data model User, and already have two DTO types created in our application, UserDTO, and UserReturnDTO.

So, do we demonstrate how to declare them? Or do we have them already declared?

Let's go further: https://docs.litestar.dev/latest/usage/dto/0-basic-use.html#defining-dtos-on-handlers

What does this example show users?

from litestar import post

from .models import User, UserDTO

@post(dto=UserDTO)
def create_user(data: User) -> User:
    return data

When I was reading it - I had no idea what User is, what UserDTO is, why do I need to use dto= at all.

I propose to refactor the first half of this guide, because right now it is really hard to understand.


[!NOTE]
While we are open for sponsoring on GitHub Sponsors and OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar

sobolevn avatar Oct 15 '24 11:10 sobolevn