04 - Testing API End Points

In the earlier post we have seen the development of endpoints using FastAPI. Post building the API endpoints we need to test them and validate them before providing the same to the front-end team.

Test the applicant creation endpoint

  • To test the application creation endpoint go to URL - 127.0.0.1:8081/api/backend
  • Open the swagger URL and open the Applicant create endpoint. Click on the try out button which will give a request body. This body will match the class defined in folder API-Backend\app\models\applicant.py ClassName - ApplicantCreateModel
  • give the following as request body { "username": "svsrikanth", "password": "TestPassword123!", "firstname": "Srikanth", "lastname": "Venkata" }
  • Post execution you should get a response from system with status code 200 which confirms the call worked fine as shown below

image.png

  • Now connect to the database and check if the data got inserted, by querying the table select * from public.applicant_login which should show the record inserted in db. image.png

  • The password is not encrypted/hashed we shall handle the case later. This confirms our API framework is able to connect to the database and make the calls. It's better to test all APIs for request response.

  • Going forward we shall come up with a testing framework to test APIs locally to make sure they are not breaking after we push code to the product branch.

  • The APIs are also not protected, so if the code is hosted anyone can make a call to retrieve/insert/delete the data in the system. It's important to protect the APIs so that only authenticated users can make the respective calls.