<reponame>GoodMonsters/Building-Data-Science-Applications-with-FastAPI
from pydantic import BaseModel, EmailStr, HttpUrl, ValidationError


class User(BaseModel):
    email: EmailStr
    website: HttpUrl


# Invalid email
try:
    User(email="jdoe", website="https://www.example.com")
except ValidationError as e:
    print(str(e))


# Invalid URL
try:
    User(email="<EMAIL>", website="jdoe")
except ValidationError as e:
    print(str(e))


# Valid
user = User(email="<EMAIL>", website="https://www.example.com")
# email='<EMAIL>' website=HttpUrl('https://www.example.com', scheme='https', host='www.example.com', tld='com', host_type='domain')
print(user)

from pydantic import BaseModel, EmailStr, HttpUrl, ValidationError


class User(BaseModel):
    email: EmailStr
    website: HttpUrl


# Invalid email
try:
    User(email="jdoe", website="https://www.example.com")
except ValidationError as e:
    print(str(e))


# Invalid URL
try:
    User(email="<EMAIL>", website="jdoe")
except ValidationError as e:
    print(str(e))


# Valid
user = User(email="<EMAIL>", website="https://www.example.com")
# email='<EMAIL>' website=HttpUrl('https://www.example.com', scheme='https', host='www.example.com', tld='com', host_type='domain')
print(user)
# Invalid email # Invalid URL # Valid # email='<EMAIL>' website=HttpUrl('https://www.example.com', scheme='https', host='www.example.com', tld='com', host_type='domain')