Add Query Params to an Express Request
In this exercise, we're building an Express app.
There's a call to
app.get() that passes in a
"/user" route and the
getUser function is an abstraction of the
makeTypeSafeGet function, so we'll look at that code first:
0:00 In this exercise, we're building an Express app. This Express app has a getUser function. The getUser basically says app.getUsergetUser. Now, getUser, what it's going to be, is we're creating this abstraction called makeTypeSafeGet. What we're doing is we have a parser, which we're parsing as the first argument to makeTypeSafeGet. Now we have a query params, which is request query, which we're getting from Express here.
0:31 What we're doing is we're returning something from query params. We want those query params to end up in req.query here. Knowing what we learned in the last explainer about request, about response, about how to handle generics, we're going to have to make this function here generic.
0:52 We're going to have to pick up what gets inferred from this parser here. The implementation itself should be fine. You may need to do some as is in there. You might be able to get away with it. You need to make sure that the right generics get passed to request handler, to request, and response. Remember, it's the query that we're interested in, not the params, not the body, just the query. Good luck.