Idiomatic way to represent pagination in JSON-LD / semantic web?

147 views Asked by At

I am working on an API that serves data that is represented as linked data. Currently responses are JSON-LD graphs. So far the API simply serves objects like this:

{ "@context": "https://my-context-url...",
  "@graph": [ {object using terms in my-context}, ... ]
}

Now I want to support pagination, because I want that response to support incomplete data when the dataset is large. The requester handles this by having limit and offset from the URL parameters, and the server may respond saying where to start the next page.

This feels like a very common pattern that would have a standard vocabulary for basic networking patterns as well as whatever data structure you like. But in my searches I can't for the life of me find a standard W3C ontology that has a term like nextPage.

My intuition is that I need to add a term like this in the response:

{ "@context": [
    "https://my-context-url...",
    { "next_page_offset":  "????"
    }
  ],
  "next_page_offset": 1000,
  "@graph": [ {object using terms in my-context}, ... ]
}

Is there such a standard? If not, am I thinking about this wrong? Possibly this is idiomatically handled without a shortcut? I am not quite clear on how to deal with verbs/relations that don't have an IRI nor a shortcut. I am new-ish to semantic web so I'm ready to believe this is supposed to be handled at some wrapper layer, or that semantic web is not intended for data that is ephemeral or something like that.

1

There are 1 answers

0
Joshua Taylor On

There's SPIN - SPARQL Syntax W3c Member Submission from 2011, which is a vocabulary for expressing SPARQL queries in RDF. If defines terms for SPARQL's limit and offset:

A LIMIT keyword is mapped into an integer value of sp:limit [http://spinrdf.org/sp#limit]. Similarly, OFFSET is stored with sp:offset [http://spinrdf.org/sp#offset].

Note that the results of LIMIT and OFFSET only really matter if there's also an ORDER BY, so you may want that, too:

If an ORDER BY statement is present in a query, then the SPIN query object will have a property sp:orderBy [http://spinrdf.org/sp#orderBy]that points to an rdf:List.

The complete ontology is available from SPIN - SPARQL Inferencing Notation.

Whether these terms are broadly used outside of representing SPARQL queries, I don't know, but the connection to a well-known query language for RDF and the fact that they're used for exactly the purposes that you're describing seems like they'd be reasonable terms to lean on.