次の方法で共有


改ページ位置の自動修正

改ページとは、クライアント アプリケーションにデータを配信するときに、大きなデータ セットをより小さく管理しやすいチャンクまたはページに分割する方法を指します。 これは、特に大量のデータを処理する場合に、API 要求のパフォーマンスと効率を向上させるために使用される一般的な手法です。 ページ分割は、1 つのチャンクに表示するデータが多すぎる場合のデータ損失を防ぐためにも使用されます。

API がページ分割されているかどうかを確認するにはどうすればよいですか?

Microsoft Fabric のページ分割された API には、これらのパラメーターが含まれています。

  • continuationUri

  • continuationToken

ページ分割されたパラメーターはどこにありますか?

ページ分割された API 応答の構造には、continuationUri パラメーターと continuationToken パラメーターが含まれており、次のようになります。

{
  "value": [
    {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",  
      "displayName": "Lakehouse",
      "description": "A lakehouse used by the analytics team.",
      "type": "Lakehouse",
      "workspaceId": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" 
    },
    {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",  
      "displayName": "Notebook",
      "description": "A notebook for refining medical data analysis through machine learning algorithms.",
      "type": "Notebook",
      "workspaceId": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" 
    }
  ],
  "continuationToken": "ABCsMTAwMDAwLDA%3D",
  "continuationUri": "https://api.fabric.microsoft.com/v1/workspaces/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/items?continuationToken=ABCsMTAwMDAwLDA%3D"
}

ファブリック REST API ではページネーションはどのように使用されますか?

ページ分割された API に対して要求を行うと、通常は プロパティの下に一連のレコードが表示されます。 レコードには、continuationUri パラメーターと continuationToken パラメーターが含まれます。 これらのパラメーターを使用すると、次のいずれかの方法を使用してレコードの次のセットを取得できます。

  • continuationUri を使用して、次のリクエストを行います。

  • continuationToken をクエリ パラメーターとして使用して、次の要求を作成します。

すべてのレコードが取得されると、continuationUri パラメーターと continuationToken パラメーターが応答から削除されるか、null として表示されます。

コード例

この例では、クライアントを作成し、「リスト ワークスペース」API を呼び出します。 continuationToken パラメーターは、空または null を返すまで、ワークスペースの次のページ分割されたチャンクを取得するために使用されます。

using (HttpClient client = new HttpClient()) 
{ 
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "<Your token>"); 
    string continuationToken = null; 
    var workspaces = new List<Workspace>(); 
    do 
    { 
        var requestUrl = "https://api.fabric.microsoft.com/v1/workspaces"; 
        if (!string.IsNullOrEmpty(continuationToken)) 
        { 
            requestUrl += $"?continuationToken={continuationToken}"; 
        } 
        HttpResponseMessage response = await client.GetAsync(requestUrl); 
        if (response.IsSuccessStatusCode) 
        { 

            // Parse the response JSON   
            var responseData = await response.Content.ReadAsStringAsync(); 
            var paginatedResponse = JsonConvert.DeserializeObject<PaginatedResponse<Workspace>>(responseData); 

            // Append the list of workspaces in the current retrieved page 
            workspaces.AddRange(paginatedResponse.Value); 

            // Check if there are more records to retrieve 
            continuationToken = paginatedResponse.ContinuationToken; 
        } 
        else 
        { 
            Console.WriteLine($"Error: {response.StatusCode}"); 
            break; 
        } 
    } while (!string.IsNullOrEmpty(continuationToken)); 
}