...
/Extending the GetQuestions Action Method for Searching
Extending the GetQuestions Action Method for Searching
Learn about GetQuestions method to handle a search request.
We'll cover the following...
We'll cover the following...
We don’t always want all of the questions to be returned in the api/questions
endpoint. Recall that our frontend had a search feature that returned questions that matched the search criteria.
Steps to handle a search request
Let’s extend our GetQuestions
method to handle a search request. To do that, follow these steps:
Add a search parameter to the
GetQuestions
method:
[HttpGet]public IEnumerable<QuestionGetManyResponse>GetQuestions(string search){var questions = _dataRepository.GetQuestions();return questions;}
Put a breakpoint on the statement that gets the questions from the repository and press “F5” to run the app:
We’ll see that the search parameter is null. Press “F5” to let the app continue.
With the breakpoint still in place, change the URL in the browser to end with ...