
Mateo Echavarria
PreguntaQue es lo que sucede cuando
127.0.0.1:8000

Mateo Echavarria
Si, es exactamente la misma que he puesto :/

Juan Jacobo Arias Ramirez
Si estás iniciando bien el servicio?
uvicorn main:app --reload

Mateo Echavarria
Este es mi codigo
#Python from typing import Optional from enum import Enum #Pydantic from pydantic import BaseModel from pydantic import Field from pydantic.networks import EmailStr, HttpUrl from pydantic.types import PaymentCardNumber #FastAPI from fastapi import FastAPI from fastapi import Body, Query, Path app = FastAPI() #Models class CustomerSeller(Enum): customer = "customer" seller = "seller" class HairColor(Enum): white = "white" brown = "brown" black = "black" blonde = "blonde" red = "red" class location(BaseModel): city : str = Field( ..., min_length = 1, max_length = 150, ) state: str = Field( ..., min_length = 1, max_length = 150, ) country: str = Field( ..., min_length = 1, max_length = 150, ) class Config: schema_extra = { "example" : { "city" : "Bello", "state" : "Antioquia", "country" : "Colombia" } } class Person(BaseModel): first_name : str = Field( ..., min_length = 1, max_length = 50, ) last_name : str = Field( ..., min_length = 1, max_length = 50, ) age: int = Field( ..., gt = 0, le = 115, ) email : EmailStr = Field(...) web_site : Optional[HttpUrl] = Field(default = None) customer_seller : Optional[CustomerSeller] = Field(default = "customer") hair_color : Optional[HairColor] = Field(default = None) is_married : Optional[bool] = Field(defauld = None) password : str = Field(..., min_length = 8 ) #DATOS DE PRUEBA class Config: schema_extra = { "example" : { "first_name" : "Mateo", "last_name" : "Echavarria", "age" : 18, "email" : "echavarria.0042@gmail.com", "web_site" : "https://teoechavarria.github.io/", "customer_seller" : "customer", "hair_color" : "brown", "is_maried" : False } } @app.get("/") def home(): return {"Hello": "World"} # Request and Pesponse @app.post("/person/new") #Obligatorio el (...) def create_person(person: Person = Body(...)): return person #Validaciones: Query Parameters @app.get("/person/detail") def show_person( name: Optional[str] = Query( None, min_length = 1, max_length=50, title = "Person Name", description = "This is the person name. It´s between 1 and 50 characters", example = "Rocio" ), age : str = Query( ..., title = "Person Age", description = "This is the person age. It´s required", example = 48 ) ): return {name : age} #Validaciones: Path Parameters @app.get("/person/detail/{person_id}") def show_person( person_id : int = Path( ..., gt=0, title = "Person Id", description = "This is the Person Id.", example = 123 ) ): return {person_id: "It exists"} #Validaciones: Request Body @app.put("/person/{person_id}") def update_person( person_id: int = Path( ..., title = "Person ID", description = "This is the person ID", gt = 0, example = 123 ), person : Person = Body(...), #location: location = Body(...) ): #results = person.dict() #results.update(location.dict()) #return results return person @app.post("/person/{person_id}/buy") def BuyWebSide( person_id: int = Path( ..., title = "Person ID", description = "This is the person ID", gt = 0 ), URLtoBuy : HttpUrl = Path(...), value : float = Path( ..., gt=0, title = "Value Website", description = "This is the value of the web site you have registered" ), PayCard : PaymentCardNumber = Path(...), person : Person = Body(...) ):