BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Deploying AI into Production with FastAPI

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

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

Uygulamalı interaktif egzersiz

İnteraktif egzersizlerimizden biriyle teoriyi pratiğe dökün

Egzersizi başlat