次のクラスが与えられた場合 (注: これらのクラスは議論中ではなく、このように存在するだけです)
class Foo {}
class Bar {}
class Event {
Foo foo;
Bar bar;
String event;
public Event(Foo foo, String event){
..
}
public Event(Bar bar, String event){
..
}
}
イベントは Foo または Bar に関連付けられますが、両方に関連付けられることはありません。
REST API を次のようにモデル化しますか (これは、API のユーザーにとって多かれ少なかれ自然に感じられます)。
POST /foo/{FOO-ID}/event
GET /foo/{FOO-ID}/event --> gets the list of events for FOO with the given id
GET /foo/{ID}/event/{EVENT-ID}
POST /bar/{BAR-ID}/event
GET /bar/{BAR-ID}/event --> gets the list of events for BAR with the given id
GET /bar/{BAR-ID}/event/{EVENT-ID}
または、どちらを好みますか (多かれ少なかれドメイン モデルを反映しています):
POST /event
GET /event?id=123&type=FOO --> gets the list events of for FOO with id = 123
GET /event?id=456&type=BAR --> gets the list of events for BAR with id = 456
GET /event/{EVENT-ID}
GET /event --> not implemented, it would logically return ALL events(both FOO and BAR), but this has no business meaning
2 つの API のうち、「最も」REST に対応しているのはどれですか? なぜ?