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.
Latihan ini adalah bagian dari kursus
Deploying AI into Production with FastAPI
Petunjuk latihan
- Create a post request endpoint at the
registerroute for user registration. - Validate the incoming user registration details using the pydantic model.
- Open a terminal and start the server by running
main.pyusing the commandpython3 main.py. - Open another terminal from the top right corner of the terminal to test the
registerendpoint 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}'
Latihan interaktif praktis
Ubah teori menjadi tindakan dengan salah satu latihan interaktif kami.
Mulai berolahraga