(window.webpackJsonp=window.webpackJsonp||[]).push([[29],{161:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){returno})),n.d(t,"metadata",(function(){returnl})),n.d(t,"rightToc",(function(){returns})),n.d(t,"default",(function(){returnp}));vara=n(2),r=n(9),i=(n(0),n(185)),o={id:"pagination",title:"Pagination"},l={id:"pagination",title:"Pagination",description:"When working with spotify responses, you will often encounter the Paging type.",source:"@site/docs/pagination.md",permalink:"/SpotifyAPI-NET/docs/next/pagination",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/pagination.md",version:"next",lastUpdatedBy:"Jonas Dellinger",lastUpdatedAt:1591299172,sidebar:"docs",previous:{title:"Proxy",permalink:"/SpotifyAPI-NET/docs/next/proxy"},next:{title:"Retry Handling",permalink:"/SpotifyAPI-NET/docs/next/retry_handling"}},s=[{value:"PaginateAll",id:"paginateall",children:[]},{value:"Paginate",id:"paginate",children:[]},{value:"Paginators",id:"paginators",children:[]}],c={rightToc:s};functionp(e){vart=e.components,n=Object(r.a)(e,["components"]);returnObject(i.b)("wrapper",Object(a.a)({},c,n,{components:t,mdxType:"MDXLayout"}),Object(i.b)("p",null,"When working with spotify responses, you will often encounter the ",Object(i.b)("inlineCode",{parentName:"p"},"Paging<T>")," type."),Object(i.b)("blockquote",null,Object(i.b)("p",{parentName:"blockquote"},"The offset-based paging object is a container for a set of objects. It contains a key called items (whose value is an array of the requested objects) along with other keys like previous, next and limit that can be useful in future calls.")),Object(i.b)("p",null,"It allows to receive only a subset of all available data and dynamically check if more requests are required. The library supports ",Object(i.b)("inlineCode",{parentName:"p"},"Paging<T>")," responses in two ways:"),Object(i.b)("h2",{id:"paginateall"},"PaginateAll"),Object(i.b)("p",null,Object(i.b)("inlineCode",{parentName:"p"},"PaginateAll")," will query all remaining elements based on a first page and return all of them in a ",Object(i.b)("inlineCode",{parentName:"p"},"IList"),". This method should not be used for a huge amount of pages (e.g ",Object(i.b)("inlineCode",{parentName:"p"},"Search")," Endpoint), since it stores every response in memory."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),"// we need the first page, every syntax can be used for pagination\nvar page = await spotify.Playlists.CurrentUsers();\nvar page = spotify.Playlists.CurrentUsers();\nvar page = () => spotify.Playlists.CurrentUsers();\n\n// allPages will include the first page retrived before\nvar allPages = await spotify.PaginateAll(page);\n")),Object(i.b)("h2",{id:"paginate"},"Paginate"),Object(i.b)("div",{className:"admonition admonition-info alert alert--info"},Object(i.b)("div",Object(a.a)({parentName:"div"},{className:"admonition-heading"}),Object(i.b)("h5",{parentName:"div"},Object(i.b)("span",Object(a.a)({parentName:"h5"},{className:"admonition-icon"}),Object(i.b)("svg",Object(a.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(i.b)("path",Object(a.a)({parentName:"svg"},{fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"})))),".NET Standard >= 2.1 required")),Object(i.b)("div",Object(a.a)({parentName:"div"},{className:"admonition-content"}))),Object(i.b)("p",null,Object(i.b)("inlineCode",{parentName:"p"},"Paginate")," is based on ",Object(i.b)("inlineCode",{parentName:"p"},"IAsyncEnumerable")," and streams pages instead of returning them all in one list. This allows to break the fetching early and keeps only 1 page in memory at a time. This method should always be preferred to ",Object(i.b)("inlineCode",{parentName:"p"},"PaginateAll")),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"}