{"id":19730521,"url":"https://github.com/begriffs/clean_pagination","last_synced_at":"2025-04-30T01:32:51.804Z","repository":{"id":13704565,"uuid":"16398491","full_name":"begriffs/clean_pagination","owner":"begriffs","description":"API pagination the way RFC7233 intended it","archived":false,"fork":false,"pushed_at":"2016-07-18T16:07:19.000Z","size":327,"stargazers_count":33,"open_issues_count":3,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-21T14:06:38.173Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/begriffs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-31T03:18:24.000Z","updated_at":"2017-11-14T14:17:53.000Z","dependencies_parsed_at":"2022-09-19T09:40:43.907Z","dependency_job_id":null,"html_url":"https://github.com/begriffs/clean_pagination","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begriffs%2Fclean_pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begriffs%2Fclean_pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begriffs%2Fclean_pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begriffs%2Fclean_pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/begriffs","download_url":"https://codeload.github.com/begriffs/clean_pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224192997,"owners_count":17271238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T00:16:38.663Z","updated_at":"2024-11-12T00:16:39.063Z","avatar_url":"https://github.com/begriffs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Clean Pagination\n\n[![Build Status](https://travis-ci.org/begriffs/clean_pagination.png?branch=master)](https://travis-ci.org/begriffs/clean_pagination)\n\nThe simplest, most flexible, most standards-compliant\npagination gem there is. Pairs nicely with\n[begriffs/angular-paginate-anything](https://github.com/begriffs/angular-paginate-anything).\n\n### Usage\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  include CleanPagination\n\n  # Using activemodel\n  def index\n    max_per_page = 100\n\n    paginate Bla.count, max_per_page do |limit, offset|\n      render json: Bla.limit(limit).offset(offset)\n    end\n  end\n\n  # Using some custom data\n  def numbers\n    paginate Float::INFINITY, 100 do |limit, offset|\n      render json: (offset...offset+limit).to_a\n    end\n  end\n  \n  # Using optional settings\n  def options\n    begin\n      paginate Foo.scope.count, max_per_page, allow_render: false, raise_errors: true do |limit, offset|\n        respond_with Foo.scope.limit(limit).offset(offset)\n      end\n    rescue RangeError\n      render json: { error: { message: \"invalid pagination range\" } }\n    end\n  end\nend\n```\n\n### Benefits\n\n* **HTTP Content-Type agnoticism.** Information about total items,\n  selected ranges, and next- previous-links are sent through headers.\n  It works without modifying your API payload in any way.\n* **Graceful degredation.** Both client and server specify the maximum\n  page size they accept and communication gracefully degrades to\n  accomodate the lesser.\n* **Expressive retrieval.** This approach, unlike the use of `per_page` and\n  `page` parameters, allows the client to request any (possibly unbounded)\n  interval of items.\n* **Semantic HTTP.** Built in strict conformance to RFCs 2616 and 5988.\n\n### Under the hood\n\nTo prevent this gem from rendering while still allowing it to set\nheaders and response codes, pass `allow_render: false` to `paginate`.\nThis may be used to avoid `DoubleRenderError` situations.\n\nTo handle the invalid request range condition in your app, pass the\n`raise_errors: true` option.  This will raise a `RangeError` which you can\nrescue (and thus control what is rendered).  Headers will still be set.\n\n[TODO: explain what the headers mean.] Until this is written you can consult\nthe tests for an idea how it works, or use a client that is compatible, such as\n[begriffs/angular-paginate-anything](https://github.com/begriffs/angular-paginate-anything).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegriffs%2Fclean_pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbegriffs%2Fclean_pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegriffs%2Fclean_pagination/lists"}