Get startedGet started for free

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.

This exercise is part of the course

Deploying AI into Production with FastAPI

View Course

Exercise instructions

  • 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}'

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise