IniziaInizia 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.

Questo esercizio fa parte del corso

Deploying AI into Production with FastAPI

Visualizza il corso

Istruzioni dell'esercizio

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

Esercizio pratico interattivo

Passa dalla teoria alla pratica con uno dei nostri esercizi interattivi

Inizia esercizio