Last active
May 13, 2018 07:10
-
-
Save cartant/ac4de5bb28cf99f107ce87b64e7c4b50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ajax } from "rxjs/ajax"; | |
| import { map } from "rxjs/operators"; | |
| export function get<T>(uri: string): { | |
| content: T, | |
| next: string | |
| } { | |
| return ajax.get(uri).pipe( | |
| map(({ response, xhr }) => ({ | |
| content: response, | |
| next: next(xhr) | |
| })) | |
| ); | |
| } | |
| function next(xhr: XMLHttpRequest): string | null { | |
| const link = xhr.getResponseHeader("Link"); | |
| if (link) { | |
| const match = link.match(/<([^>]+)>;\s*rel="next"/); | |
| if (match) { | |
| return match[1]; | |
| } | |
| } | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment