2017-12-20 26 views
0

resultとresult-countを取得するために別々のAPIを作成する必要があるかどうか混乱します。または、結果APIのクエリ文字列に基づいてカウントを取得する必要があります。クエリ文字列は、そのリソースのフィルタリングに使用されている私にREST API:結果と結果の数を別々のAPIにする必要がありますか?

/api/results/ : Fetches all records 
/api/results/?city=1: Fetches all records with city=1 
/api/results/?iscount=1: Fetches the count of records i.e. list of cityId and count of record for respective cityId 
/api/results/?city=1&iscount=1: Fetch the count of record for cityId=1 

OR

/api/resultcount/: Fetches the count of records i.e. list of cityId and count of record for respective cityId 
/api/resultcount/?city=1: Fetch the count of record for cityId=1 

、私はカウントを取得するための別のAPIを作成するに賛成しています。意見?

答えて

0

カウントを取得するための別のポイントを作成する必要はありません。代わりに、カウントの詳細をレスポンスヘッダーに送信できます。

以下のようなもの、

/API /結果/(GETメソッド)になります - これは結果を返します。

/api/results /(HEADメソッド) - これは、応答ヘッダーの結果カウントを返します。

下記のリンクをご覧ください What’s the best RESTful method to return total number of items in an object?

関連する問題