REST API: Offset parameter larger then resultset size causes weird behavior

1 view
Skip to first unread message

Matthias Vandermaesen

unread,
Sep 25, 2015, 9:33:50 AM9/25/15
to Europeana API forum
Hi,

I accidentally generated this API call which returns a weird, inconsistent resultset:


Response:

{
apikey: "api2demo",
action: "search.json",
success: true,
requestNumber: 999,
itemsCount: 0,
totalResults: 3
}

The problem here is that totalResults says that there are 3 items, but no "items" property is present.  If you app relies on a check if totalResults > 0 before proceeding to parse the "items" property, then you are going to run into breaking errors.

The cause of this bug is the start=20 parameter.  In this case: I'm trying to fetch items starting from an offset position (20) which is larger then the totalResults parameter (3)
Any application should of course check itemCount as well because that shows the number of items returned in the current call.

I would like to suggest an improvement:  Always return the "items" property but return an empty array of items if itemscount = 0.  That way, the API avoids breaking dependent applications because a property is suddenly not present anymore.


With regards,


Matthias Vandermaesen

Digitale dataconservator | Vlaamse Kunstcollectie VZW

matthias.v...@vlaamsekunstcollectie.be

http://www.vlaamsekunstcollectie.be 

Abrahamstraat 13

9000 Gent


M +32 (0)486 75 56 23

T +32 (0)9 225 49 34

Gordea Sergiu

unread,
Sep 28, 2015, 8:41:56 AM9/28/15
to europe...@googlegroups.com

Well …

 

I see no inconsistence here, with regard to the request and response…

I don’t think that the API should be responsible for preventing inconsistencies in the search queries …. Especially because you have many possible combinations.

 

It is a common/standard practice in JSON serialization to not serialize null properties. So … how would the empty array help client to understand that actually start is greater than total results?

As the query is technically correct and the response is also consistent with the query, I would say that it is not appropriate to respond with an error message.

 

What might be useful from my perspective is to add a “range” in the response, for which [-1 , -1] would mean “out of range”, if the goal is to better understand the meaning of the results.

 

BR,

 

Sergiu

--
Visit Europeana Labs for API Documentation, Open Datasets, and our Apps Showcase - http://labs.europeana.eu
---
You received this message because you are subscribed to the Google Groups "Europeana API forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to europeanaAPI...@googlegroups.com.
To post to this group, send email to europe...@googlegroups.com.
Visit this group at http://groups.google.com/group/europeanaAPI.
For more options, visit https://groups.google.com/d/optout.

Vladimir Alexiev

unread,
Oct 1, 2015, 12:13:53 PM10/1/15
to Europeana API forum
Agree with Sergiu, you can easily check whether an "items" key is present before accessing it
Reply all
Reply to author
Forward
0 new messages