Implementing pagination | ASP.NET Core 5 REST API Tutorial 26

preview_player
Показать описание

Hello everybody I'm Nick and today I will show you how you can easily add pagination in your REST API in ASP.NET Core. We will use a simple approach which is easy to follow and adds the basics for a fully functional pagination. You can of course expand on it if you want.

Don't forget to comment, like and subscribe :)

Social Media:

#tutorial #rest #api
Рекомендации по теме
Комментарии
Автор

Hi Nick, thanks a lot for your series. For UriService.GetAllPostsUri() method should be used uri, not _baseUri as it was in the video. The correct line is:
var modifiedUri = QueryHelpers.AddQueryString(uri.ToString(), "pageNumber",

otherwise, NextPage and PreviousPage are incorrect

MrMadcatsam
Автор

Thank you very much for your clear explanations . Very valuable as usual .

zakizaz
Автор

very nice tuto, Good work, i am watching all of your tuto.

shivashivakumara
Автор

Any plans down the line to structure the project in to micro services

samg
Автор

Good video. It may be safer to register the IUriService with dependency injection as a scoped object since it depends on the HttpContext and Host. Which both can be different based on the request.

zeidderhally
Автор

Thank you so much for the great paging code. Can you give me an idea of ​​how to handle the query for example, getHeaderItems, along with childItems. The problem is that if the relationship diagram is not designed, it is not automatically pulled into the Entity Framework.

generalexplorer
Автор

I know this is an old viedo but I just found it and there are some weird stuff going on that I can't help myself noticing. First of: the generated next/previous page url are wrong: they reference the root url of the web api and not the "api/v1/post" route. Also, the registration of the UriService is done using a singleton, meaning it will generate a single instance for every call, that will break the url generation when you're calling another route (for instance "api/v1/tags"). Thanks for your video and your chanel, a great source of inspiration for my work ;)

lpussacq
Автор

I would think of adding a total entries count to the response, usually it would be beneficial to display some fast forwarding by displaying multiple page numbers in the footer or header.

vasiliioleinic
Автор

i was getting an error on automapper at start up. I had to add this :

services.AddAutoMapper(Assembly.GetAssembly(typeof(PaginationFilter)),

and i was also getting an error when i was getting the IHttpContext Acessor. I had to add this before:



Btw i was testing this with postman but when i click to follow link i can't see anything(page number with the data ). is it postman related or in the code(even tho i did everything you did in the video)


The rest is working fine.

stunna
Автор

I like this approach but pagination would normally include a total count, would it not?

PierreGadea
Автор

Great educational content. Learned a lot. Can you do something with unit testing this api?

scubaservice
Автор

Hello Nick Chapsas, I'm new in .net core. I faced error (0x80131904): Incorrect syntax near 'OFFSET'.
Invalid usage of the option NEXT in the FETCH statement. In the PostServices.cs this line : return await _dataContext.Posts.Include(x => x.Tags)

How can I solve this problem?

viralpatel
Автор

Any chance we could get a video on a preferred logging pattern? Best way to log bad requests/failing business logic for whatever reason

mrFwar
Автор

What Visual Studio Code extensions are you using? Thanks

rdjah
Автор

Any concerns of not setting paging in repose header?

ArunaRanatunga
Автор

Why not just return the path part of the uri? it may be incorrect if the service is behind a gateway.

csharp
Автор

If last page record count<= pageSize & there's not record in next page it must return nextpage=null, without total count how can do it?🤔

baharefeizi
Автор

I don't understand the value of mapping from PaginationQuery to PaginationFilter, why we are not using PaginationQuery directly ?

elawady
Автор

Try to use Phema.Routing instead of baseUrl + It is strongly types and works with mvc attribute routing

sergeyshaykhullin
Автор

Good tutorial, but you complicated very much in conception simple, has one conception called KISS, so you not respect this conception. But I using this video to my problem in my work, thank you

DastanOficial