How to Using Pagination in oc-api-plugin

Octobercms plugin: oc-api-plugin

This plugin gives you API integration to your OctoberCMS. You can return data in JSON response.

However API endpoint will return all the records if you use code given in documentation. Below code will not be able to return paginated data.

class PostsAPI extends ApiController
{
    public function index()
    {
        $item = Post::get();
        return $this->respondwithCollection($item, new PostTransformer);
    }

If you need to return paginated JSON data you need to use respondWithPaginator method.

class PostsAPI extends ApiController
{
    public function index()
    {
        $postPaginator = Post::paginate(); // use paginate
        return $this->respondWithPaginator($postPaginator, new PostTransformer);
        // use this method ^
    }
js interview questions