0

私はStudentsControllerを持っており、現在次の作業を行っています:

http://mycompany.com/api/v1/students   <-- returns list of students
http://mycompany.com/api/v1/students/5 <-- returns student with Id = 5

2013 年のクラスのすべての学生を返す必要がありますが、もちろん以下は機能しません。

http://mycompany.com/api/v1/students/2013 <-- won't work, because it would look for the student with Id = 2013

私はこれを行うことができます:

http://mycompany.com/api/v1/students?gradclass=2013

しかし、次のようなクエリ文字列なしで意味のある方法があるかどうか疑問に思っています。

http://mycompany.com/api/v1/students/gradclasses/2013

上記のようなものは理にかなっていますが、これはあまり意味がありません:

http://mycompany.com/api/v1/students/gradclasses <-- this sort of makes no sense

また、ルーティングを使用して、適切なソリューションを見つけたら、どのようなアプローチでセットアップしますか?

これは価値がありますか?ベストプラクティスは何ですか? REST および GET クエリ パラメータのベスト プラクティスを見つけるのに苦労しています。

4

2 に答える 2

0

「2013年度卒業生」というのが一つの見方です。そして、API を /type/view/params として構成します。つまり: http://mycompany.com/api/v1/students/byclass/2013
http://mycompany.com/api/v1/students/withJobOffer
http://mycompany.com/api/v1/students/repeaters/ 2012年

実際、ビューは重複する可能性があります。それはもっと複雑です。次に、クエリ文字列を処理する必要があります: http://mycompany.com/api/v1/students?class=2013&withJobOffer=true&repeaters=2012

于 2013-11-12T00:02:56.127 に答える