December 2019
Intermediate to advanced
598 pages
12h 21m
English
Let's interact with the REST API to search for questions using our http function. This is very similar to what we have just done, so, we'll do this in one go:
export const searchQuestions = async ( criteria: string,): Promise<QuestionData[]> => { try { const result = await http<undefined, QuestionDataFromServer[]>({ path: `/questions?search=${criteria}`, }); if (result.ok && result.parsedBody) { return result.parsedBody.map(mapQuestionFromServer); } else { return []; } } catch (ex) { console.error(ex); return []; }};
We make a request to the questions endpoint with the search query parameter containing the criteria. We return the response body with created Date objects if the request is successful or ...
Read now
Unlock full access