Coder Social home page Coder Social logo

node-paginate-anything's Introduction

node-paginate-anything

Build Status Dependency Status devDependency Status

nodejs server side module for angular-paginate-anything

This nodejs module add the required headers in the http response to paginate the items. This is a rewrite of clean_pagination

Install

  npm install node-paginate-anything

Usage

  var paginate = require('node-paginate-anything');
  
  var queryParameters = paginate(ClientRequest, ServerResponse, totalItems, maxRangeSize);
  
  mongooseQuery.limit(queryParameters.limit);
  mongooseQuery.skip(queryParameters.skip);
parameter Description
ClientRequest clientRequest object from the native http module or from an express app.
ServerResponse ServerResponse object to modify before sending the http response.
totalItems total number of items in the result set.
maxRangeSize angular-paginate-anything send is own requested range in the request, this parameter specify the maximum value.

Benefits

  • HTTP Content-Type agnoticism. Information about total items, selected ranges, and next- previous-links are sent through headers. It works without modifying your API payload in any way.
  • Graceful degredation. Both client and server specify the maximum page size they accept and communication gracefully degrades to accomodate the lesser.
  • Expressive retrieval. This approach, unlike the use of per_page and page parameters, allows the client to request any (possibly unbounded) interval of items.
  • Semantic HTTP. Built in strict conformance to RFCs 2616 and 5988.

node-paginate-anything's People

Contributors

bitdeli-chef avatar demisx avatar polo2ro avatar travist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-paginate-anything's Issues

Properly handle the case of zero rows in result

@dnauck discovered an issue in the clean_pagination gem where it improperly considers a range request 0-n invalid when the there are no results. Your node module may be susceptible to the same bug. Here is how I fixed it:

begriffs/clean_pagination@f543249

Also we determined that the best response in this case is status code 204 (no content), Content-Range: */0, and an empty body. Angular-paginate-anything v2.5.2 interprets this response appropriately.

Calculated Link header values

There are total 22 items in DB and my max-range-size = 5. Is it expected behavior that requesting this range:

GET /v1/ads?classId=2
Range-Unit: items
Range: 5-11

return Link header like this?

Link: '</?classId=2>; rel="next"; items="10-16", </?classId=2>; rel="last"; items="20-26", 
        </?classId=2>; rel="prev"; items="0-6", </?classId=2>; rel="first"; items="0-6"'

My questions:

  1. Why the prev and first are set to "0-6" when I am already expecting to get 5 and 6 in this request?
  2. Shouldn't the next and last items to be set to "20-21", since there are only 22 items in the DB matching this request

Thank you. Just trying to understand how this should work.

Please create a new version.

You have pulled in a lot of changes and our library @ formio/formio is still not able to pull in any official version. Please release a 0.0.6 or even a 1.0.0 would be good. ;)

Thanks,

Travis.

Propose to switch to camelCase

What do you think about changing your variables from snake_case to Javascript standard camelCase? Looks like you are coming from a C-like programming background. I can help you to make you module more Javascript friendly. Let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.