Friday, December 21, 2018

Question about best practices for storing data between requests (pagination) and calling an API

I have been working on back-end for a few months now and have built a few APIs. I'm starting on the front end with a very simple web application. I am using .Net Core 2.2 and am using Razor Pages instead of MVC as my app is not complex enough to warrant MVC.

Paginated data is built into my API so each request returns a header with total pages, page size, current page, next page link, prior page link, etc. I don't load the entire data at once and by default serve a subset of the data (e.g. pagenum=1&pageSize=5) which the user can paginate through via links from the web application.

 

I have a page located at /Meetings/{pageNumber:int?}. The pagenum is optional and I am using a default value of 1 in case its not provided (via the PageModel property). All other parameters like pagesize, filters are provided via query strings. I'm not sure on the best practice for storing these values across page requests.

 

I currently am using a form to paginate data (i.e. each page number is a submit button with a asp-route-{value} attribute. This is because I wanted the user to be able to change the page size via a dropdown and the reason why I am not using links. I submit page number, page size, and filters with each request to paginate.

 

I had a couple question on how to handle the app functionality:

  • I am currently using TempData to store pagesize, pagenumber, filters, etc when users navigate between requests (like editing/creating). Someone else suggested using localstorage though and avoid tempdata. I am also using the cookie tempdata provider so unsure if this incorrect and should replace this with session tempdata provider. I am wondering if TempData would be faster as its stored server side and the data does not need to persist between sessions.

  • Should I change my approach for pagination to use links instead of a form? I was thinking about converting the pagesize to use JS instead of using a form (i.e. whenever user changes page size, use JS to post back to the web app and change the result list size). This will also allow my form to be replaced with links instead and I can include page size, filters, and sorts in my pagination link.

  • If using localstorage, I'll have to end up passing data from the client side to my server side web application each time. Is it pretty normal to do a post from JS -> Server web app -> Server web API. Or do you typically cut out the web app out completely and replace with a JS only app that calls the API directly?

Question about best practices for storing data between requests (pagination) and calling an API Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team