odata-client-php
odata-client-php copied to clipboard
Question about @odata.nextLink
For example we have request like this
$people = $odataClient->from('People')->take(2)->get();
How I can get access to @odata.nextLink
@t3Golden Did you figure this out?
As best I can tell, ODataRequest::execute() calls ODataResponse::getResponseAsObject() which extracts the value array from the returned json object and discards everything else. Eventually that array gets passed to the Illuminate Collection class, so I'm not even sure how one would go about addressing the loss of useful metadata without a breaking change.
@jbramleycl that is correct. However, we're looking at returning a custom collection or LengthAwarePaginator that is still an iterator to keep backward compatibility while enabling you to page through multi-page results.
Any process on this yet? Currently, I am doing a count() first, and then I page through the results doing a skip which is a nasty workaround since OData is providing the next page. Would be really great to have the @odata.nextLink property available somehow.
:+1: I just ran into that problem as well. This issue is open for 4 years now. Is there a solution now? Otherwise I will build an own implementation.
i. need. this.
working with an api that enforces pagination. can you provide your wip so we can take it from there, please?
This is now supported. Setting $odataClient->setEntityReturnType(false) will allow you to get the full ODataResponse object, from which you can then call getSkipToken(),
@glaszig, @mschop, @Cabag, @jbramleycl, @stefantalen, @drblitz-weblab,
Sorry for the delay on this.
Please take a look at PR142 and feel free to pull down the source branch feature/paging-with-lazycollection which adds support for native paging over the paginated OData response using LazyCollection via new cursor methods on the Builder and ODataClient.
Using the new cursor method on the Builder, you can page through the paginated response like so:
// Request 8 records per page (library default is 25)
$odataClient = new ODataClient('https://services.odata.org/V4/TripPinService', function($request) {
$request->headers[RequestHeader::PREFER] = Constants::ODATA_MAX_PAGE_SIZE . '=' . 8;
})
// Or, using the new 'pageSize' method on the Builder
$data = $odataClient->from('People')->pageSize(8)->cursor();
$totalRecordCount = $data->count(); // Will return 20, which is the total number of 'Person' records in the Person EntitySet
$firstPerson = $data->first(); // Will return the first person in the EntitySet (Russell Whyte)
$lastPerson = $data->last(); // Will return the last person in the EntitySet (Krista Kemp, from page 3 of the paginated results)
// Skip the first 8 records (page 1) and get the first person on page 2 (the 9th Person)
// This will issue a request to the second page in order to obtain the 9th person in the EntitySet (Marshall Garay)
$ninthPerson = $data->skip(8)->first();
Still doing some additional review and testing, but wanted to get some feedback before merging.
Updated wiki with paging examples here.