Aan de slagBegin gratis

Testing custom validators

After defining custom validators, you need to add that validator to the API endpoint and ensure it is working as expected.

The system should ensure users with valid email addresses are able to register. Here you need to create a simple endpoint that expects user details(username, email and age) in the request. You need to add the pydantic model to the endpoint and test the endpoint for invalid email address using cURL command, provided in the instructions.

Deze oefening maakt deel uit van de cursus

Deploying AI into Production with FastAPI

Bekijk cursus

Oefeninstructies

  • Create a post request endpoint at the register route for user registration.
  • Validate the incoming user registration details using the pydantic model.
  • Open a terminal and start the server by running main.py using the command python3 main.py.
  • Open another terminal from the top right corner of the terminal to test the register endpoint with invalid email address: curl -X POST "http://localhost:8080/register" -H "Content-Type: application/json" -d '{"username": "jane_doe", "email": "[email protected]", "age": 30}'

Interactieve oefening met praktijkervaring

Zet theorie om in actie met een van onze interactieve oefeningen

Begin oefening