Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active May 13, 2018 07:10
Show Gist options
  • Select an option

  • Save cartant/ac4de5bb28cf99f107ce87b64e7c4b50 to your computer and use it in GitHub Desktop.

Select an option

Save cartant/ac4de5bb28cf99f107ce87b64e7c4b50 to your computer and use it in GitHub Desktop.
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