Data fetching plays a crucial role in web development, given its importance in retrieving data from various sources to provide dynamic and interactive experiences to users.

Applications of API requests in the survey application

Listed below are the areas where we would need to make fetch requests in the survey project:

  • Authentication: Certain features of the application are restricted to registered administrator users. These features include survey creation/update and viewing survey responses. To ensure only the administrator user has access to these features, we need to authenticate the user using their username/email and password combination. These credentials would be saved on the API server’s database, requiring the client to make a fetch request to the API server for authentication.

  • Data storage: Surveys designed by the administrator user need to be persisted for easy retrieval and distribution. The client posts the designed survey data to the API server endpoint, which saves this data to a dedicated table on the database with a unique id for reference. Whenever the administrator needs to retrieve a survey they had initially created, they can make a request with the id of the survey to the API server and the saved data should be returned.

Additionally, upon submission of responses from a survey taker, the client posts the data to the API server endpoint. The API server saves this data to a table on the database dedicated to survey responses, making it visible for the administrator whenever they need to view the responses.

  • Data retrieval: Dynamic content, such as the survey description, title, and questions, needs to be fetched whenever a survey taker decides to begin filling out a survey. These data are retrieved by making a fetch request with the survey’s unique id to the API endpoint. The response from the API endpoint is then rendered on the page as the survey details, questions, and options.

Administrators can also retrieve the configuration of the surveys they once created to view and update them with additional details using a fetch request to the API endpoint. Additionally, they can fetch the responses to the surveys created by them to analyze the data from the survey takers.

Get hands-on with 1200+ tech skills courses.