Recall that the home screen of our app, as implemented in Chapter 3, Getting Started with React and TypeScript, shows the unanswered questions.
So, let's implement an action method that provides this functionality:
- Let's fully implement the method:
[HttpGet("unanswered")]
public IEnumerable<QuestionGetManyResponse>
GetUnansweredQuestions()
{
return _dataRepository.GetUnansweredQuestions();
}
The implementation simply calls into the data repository GetUnansweredQuestions method and returns the results.
Notice that the HttpGet attribute contains the string "unanswered". This is an additional path to concatenate to the controller's root path. So, this action method will handle GET requests to the api/questions/unanswered path.
- Let's give this a try by running the app in a browser by entering the api/questions/unanswered path:
We get the unanswered question about state management as expected.
- Stop our app running by pressing Shift + F5 so that we can write another action method.
That completes the implementation of the action method that handles GET requests to api/questions/unanswered.