2

I have a case where I need to expose the following server routes:

/cats/:catId /cats?name=:name

How should my server routes look? I tired this:

app.route('/cats/:catId')
        .get(cats.read)

app.route('/cats?name=:name')
        .get(cats.getByName)

But that doesn't work. I seem to get routed to /cats in that case.

Should I have a route like this, or should I just do a switch in my server controller to handle the query strings as appropriate?

4

1 に答える 1

3

あなたはルートの競合に陥っています。あなたは最初のルートにフォールバックを行っています。あなたは文字列ので定義しています。可能であればパターンを変更し、それを避けるために、安らかな命名規則に従うことをお勧めします。の場合:

app.route('/cats/id/:catId').get(cats.read)
app.route('/cats/name/:name').get(cats.getByName)

それは理にかなっていますか?

于 2014-09-04T01:04:21.787 に答える