Skip to content
Discussion options

You must be logged in to vote

Hello @rigens, you can achieve the same with:

from fastapi import FastAPI

app = FastAPI()


@app.post("/post-strings")
async def post_strings(strings: list[str]):
    return strings

As FastAPI allows you to use types used for Pydantic fields, there's no need to use RootModel, it's not officially supported, because you can achieve the same in better and simpler ways.

If you need to modify things further, you can also use additional Pydantic validators: https://docs.pydantic.dev/latest/concepts/validators/

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants