-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle query params #71
Comments
Oh, also, is there a way to make the |
Why is this project not using
|
I tried the above suggestion and that didn't work for me. I don't have time to investigate why (will try later) but I thought I'd let you know. |
In case it's helpful, here's what I have tried: rest.get(`${apiUrl}/books`, async (req, res, ctx) => {
console.log('here we go')
if (!req.query.hasOwnProperty('query')) {
return ctx.fetch(req)
}
const {query} = req.query
let matchingBooks
if (query) {
matchingBooks = matchSorter(allBooks, query, {
keys: [
'title',
'author',
'publisher',
{threshold: matchSorter.rankings.CONTAINS, key: 'synopsis'},
],
})
} else {
// return a random assortment of 10 books not already in the user's list
matchingBooks = getBooksNotInUsersList(getUser(req).id).slice(0, 10)
}
await sleep()
return res(ctx.json({books: matchingBooks}))
}), |
Yes, accessing I've decided to parse the URL using The usage of res.get('/api/books', (req, res, ctx) => {
const bookId = req.query.get('id')
return res(ctx.json({ bookId })
}) |
Released
@kentcdodds, could you please try it? I hope it works well for your use case. |
Yup, this works: rest.get(`${apiUrl}/books`, async (req, res, ctx) => {
if (!req.query.has('query')) {
return ctx.fetch(req)
}
const query = req.query.get('query')
let matchingBooks
if (query) {
matchingBooks = matchSorter(allBooks, query, {
keys: [
'title',
'author',
'publisher',
{threshold: matchSorter.rankings.CONTAINS, key: 'synopsis'},
],
})
} else {
// return a random assortment of 10 books not already in the user's list
matchingBooks = getBooksNotInUsersList(getUser(req).id).slice(0, 10)
}
return res(ctx.json({books: matchingBooks}))
}), Thanks! |
URI에 쿼리를 포함하지 않는 게 맞은듯 해서(mswjs/msw#71) 수정함 또한 스케쥴의 요일이 대문자가 아니면 제대로 변환되지 않아서 수정함 또한 추천 핸들러만 작동시킬 수 있도록 따로 분리함
I'm pretty sure this is a bug in
pathToRegExp
(why is this project not usingpath-to-regexp
like many other path parsers?). But if I provide the following URL:http://localhost:8989/api/book?query=:query
this gets parsed to the following regex:http:\/\/localhost:8989\/api\/book?query=(?<query>.+?(?=\/|$))\/?
You may notice that the
?
for the search string is not escaped. I believe that to be a bug in the parser. If I escape it myself, then things work just fine.The text was updated successfully, but these errors were encountered: