create a factory for doing pagination of rest resources