FastAPI Request Sample Data - Sample data from the argument, Body

Let's learn how to put sample data into API methods.

From parameters like the body but you can also apply it to those you can see:

  • Path()
  • Query()
  • Header()
  • Cookie()
  • Body()
  • Form()
  • File()

We can also define example data. In this video we will see that it is using the examples and in the next one using the open examples, so for that it is a very similar structure to the one we already have. It is also important to note that if we define it at the model level and then define it at the argument level, these overwrite those that are defined at the model level:

@task_router.put("/",status_code=status.HTTP_200_OK)
def update(index: int, task: Task = Body(
    examples=[
                {
                   "id" : 123,
                    "name": "Salvar al mundo",
                    "description": "Hola Mundo Desc",
                    "status": 'PENDING',
                    "tag":["tag 1", "tag 2"],
                },
                {
                    "name": "Bar",
                },
                {
                    "name": "Baz",
                },
            ],
)):
    ***

- Andrés Cruz

En español

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 1d 13:41!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

View books
¡Become an affiliate on Gumroad!