An open API service indexing awesome lists of open source software.

https://github.com/frezyx/http_pagination

Parses a link header (web links) and returns pagination data
https://github.com/frezyx/http_pagination

dart dart-package dart-parser dartlang dio flutter http pagination pagination-functionality pagination-library pagination-links

Last synced: about 1 month ago
JSON representation

Parses a link header (web links) and returns pagination data

Awesome Lists containing this project

README

          

# Http pagination

Http headers pagination parser

Inspired by js lib [parse-link-header](https://github.com/thlorenz/parse-link-header)

## Features

Parses a link header [(web links)](https://datatracker.ietf.org/doc/html/rfc5988) and returns pagination data

Works both with pages and cursor pagination

## Getting started

```yaml
dependencies:
http_pagination: ^0.2.2
```

## Usage

Pages pagination

```dart
import 'package:http_pagination/http_pagination.dart';

final headers = {
'link': [
'; rel="next", ' +
'; rel="prev", ' +
'; rel="last"'
],
};
final pagination = PagesPagination.fromHeaders(headers);
print(pagination); // PagesPagination(first: null, next: 3, prev: 1, last: 5)
```

Cursor pagination

```dart
import 'package:http_pagination/http_pagination.dart';

final headers = {
'link': [
'; rel="first", ' +
'; rel="next", ' +
'; rel="prev", ' +
'; rel="last"',
],
};

final pagination = CursorPagination.fromHeaders(headers);
print(pagination); // CursorPagination(first: a, next: b, prev: c, last: d)
```