Skip to content

API versions ​

We're evolving the BlackLab REST API over time, using versioning.

There's currently two supported versions:

  • 4.0: default API for BlackLab 4.x, deprecated but still supported in BlackLab 5.x.
  • 5.0: default API for BlackLab 5.0 and up. Corpus-related endpoints are now under /corpora/CORPUSNAME/... instead of /CORPUSNAME/.... Various inconsistencies have been cleaned up.

To find out which API version your BLS defaults to, check the server info page (/). Look for the key blacklabResponse.apiVersion. BLS is using that API version by default.

Don't worry, not every version of BlackLab will get a new API version. The intention is to keep API v5 for the next several major BlackLab versions.

Staying on the older API for now ​

If you use BlackLab v5.0 and need time to migrate your client to the new API, you can keep using the older API v4 for now. Do note that BlackLab v6.0 will only support API v5.

The default API version can be set in the server configuration or on a per-request basis.

To set the default API version for the server, configure parameters.api in your blacklab-server.yaml:

yaml
parameters:
  # default to API v4 while we plan our migration to API v5
  api: 4

On any BLS request, you can also override the default version using the api parameter. So if you haven't changed the default as shown above but want to use API v4 for a specific request, you can use:

# Server info request explicitly using API v4:
https://myserver/blacklab-server/?api=4

# Corpus hits request explicitly using API v4:
https://myserver/blacklab-server/MY_CORPUS/hits?api=4&...

Migrating to the new API ​

API changes from 4.0 to 5.0 ​

API v5.0 was introduced in BlackLab 4.0 and is the default API starting in BlackLab 5.0.

Note that the new endpoints (like /corpora/CORPUSNAME/hits) always "speak" API v5. So where we say "changed" or "removed" below, we usually mean that compared to the equivalent old endpoint (/CORPUSNAME/hits).

Removed ​

All these were deprecated in API v4.0, and v5.0 removes them:

  • Server info page removed the indices key. Use corpora instead.
  • Document info page (/docs/DOC_PID) and results pages no longer include metadataFieldDisplayNames, metadataFieldGroups or docFields. This information can be found on the corpus info page and need not be sent with each document info request.
  • Results pages don't include captureGroups anymore. Use matchInfos instead.
  • If you specify subcorpussize=true (formerly called includetokencount), summary doesn't include the tokensInMatchingDocuments key anymore. This information is available under the subcorpusSize key.

Changed ​

These are breaking changes compared to v4.0. Make sure you update your client accordingly.

  • Starting with BlackLab 5.0, old endpoints related to corpora (e.g. /blacklab-server/MY_CORPUS/hits?...) will fail with a descriptive error unless you explicitly specify api=4 or configure the default API version to be 4. Prefer using the new /blacklab-server/corpora/MY_CORPUS/hits?... endpoints that were introduced in BlackLab 4. These endpoints can only 'speak' API v5.
  • All XML responses:
    • XML responses don't use dynamic values as element names anymore, but instead adopt a <entry><key>...</key><value>...</value></entry> structure. This avoids problems with and simplifies maintaining the (less-used) XML format. Mainly affects summary/searchParams, docInfos, users[] in /sharing response.
    • Wherever the XML used attributes for map entries, e.g. <entry key="key">value</entry>, this was changed to <entry><key>...</key><value>...</value></entry> as well.
  • server, corpus, field info:
    • indexName in corpus info has been replaced with corpusName. indexName was dropped from the field info response.
    • Corpora, metadata and annotated field and annotations report certain properties (such as displayName, description) inside a custom block now etc. These are all ignored by BlackLab but may be useful for client applications such as BlackLab Frontend. They are only included in responses if you specify custom=true.
    • Document and token count have been grouped under a count key. A parallel corpus will also include a docVersions key that gives the total number of document versions. annotatedFields will also include a count key that gives the number of docs/tokens for that field.
  • Results pages:
    • summary has been restructured to group related values together under params, resultWindow and resultStats. Subkeys have been renamed for clarity.
    • summary.params are now returned as the correct type: string (e.g. pattlang), integer (e.g. first), boolean (e.g. waitfortotal) or JSON (e.g. scorer).
    • response keys left/right have been replaced with before/after in the /hits response.
    • docInfos now have a metadata subobject instead of mixing metadata with mayView and lengthInTokens.
    • When using usecontent=orig, the value of escapexmlfragment now defaults to true, so XML fragments from the document will be escaped as CDATA. Set it to false to include them as part of the XML structure instead (the old default).

API changes from 3.0 to 4.0 ​

Below are all the differences between API version 3.0 (up to BlackLab 3.x) and 4.0 (from BlackLab 4.0).

API v4.0 was intended to prepare for API v5.0 by adding alternative keys to several responses (e.g. corpora on server info page, matchInfos in hits response). The original keys are still present for backwards compatibility, but they are deprecated and API v5.0 removes them.

Changed ​

  • Corpus info page (/CORPUSNAME):
    • Two keys were renamed to be more consistent: in the versionInfo block, blacklabVersion and blacklabBuildTime are now spelled with a lowercase l, just like on the server info page. This is unlikely to break any clients.
    • A key was added: blacklabScmRevision, giving the short Git commit hash for this version of BlackLab.
  • Annotated fields:
    • displayOrder will no longer include internal annotations (e.g. punct and _relation, previously called starttag), as these are generally not meant to be displayed as search fields.

Added ​

  • Server info page:
    • New key added (/): apiVersion (valid values: 3.0, 4.0, 5.0; assume 3.0 if missing)
    • In addition to indices, the new corpora key was added that provides the same information in a slightly different format. You should use corpora instead of indices for future compatibility.
    • In addition to being reported under fieldInfo, pidField is now also a top-level key. You should use this version of the key for future compatibility. (the other special fields in fieldInfo will be moved to custom in v5)
  • Corpus info page:
    • mainAnnotatedField indicates which of the annotated fields is the main search field. This is useful if there's more than one annotated field, e.g. in case of parallel corpora.
  • Search (hits) operations:
    • The patt parameter may also be specified as a JSON query structure. This will be detected automatically, or you can set pattlang to json to make it explicit.
    • In the JSON response, summary will now include a pattern object containing: a json key that giving the JSON query structure; a bcql key giving the (re-)serialized pattern in BlackLab Corpus Query Language; a fieldName key giving the search field, e.g. "contents"; and a matchInfos key giving the match info groups from the query with their types (span, tag, relation, list). You can use this to convert between the two representations, e.g. for query builders (or use the new /parse-pattern endpoint, see below). The XML response does not contain the json object.
    • If you specify subcorpussize=true (formerly called includetokencount), summary will include a subcorpusSize key that gives the number of docs, docVersions (for parallel corpora) and tokens in the subcorpus matching the search pattern. For parallel corpora, numbers of docs and tokens will also be specified per version under the annotatedFields subkey.
    • In addition to captureGroups, matchInfos will be reported that includes the same information as well as any inline tags and relations matched. You should use this instead of captureGroups for future compatibility.
    • before/after are the new, preferred alternatives to left/right,e.g. when sorting/grouping on context. Not all languages are LTR, so this makes more sense. Existing endpoints still use left/right in the response for compatibility, but new endpoints have been updated as well. These properties can now get a number of tokens as an extra parameter, e.g. before:lemma:i:2.
    • For grouping on context, wordleft/wordright have been deprecated. Use before/after with 1 token instead.
    • Grouped results also include a properties key that gives the values for the individual properties used for grouping. This is an alternative to identityDisplay, which clients would sometimes have to parse to display it in their preferred way.
    • context is the new name for the wordsaroundhit parameter and supports more options (separate before/after, whole sentence, etc.)
  • Pages that list values for fields, tags, etc. now support the limitvalues parameter. This parameter defaults to 200, but can be set higher if you need really long value lists.
  • New endpoints were added for all operations on corpora, at /corpora/CORPUSNAME/... (for now alongside existing endpoints /CORPUSNAME). These endpoints are available in BlackLab v4 but only "speak" API v5 (see below). You should move to these endpoints for future compatibility.
  • A new endpoint /parse-pattern was added that allows you to parse a CorpusQL or JSON query structure pattern without actually executing the search.
  • Field info will return relations block containing all the spans ("inline tags") and relations indexed in the corpus.
  • Doc info on results pages and document info page: the new tokenCounts array gives token counts for all annotated fields. The first annotated field is the main one, which has the same value as lengthInTokens.
  • When using usecontent=orig, you can now specify escapexmlfragment to control whether XML fragments are escaped as CDATA or not. This defaults to false for API v4 and older, but will be true for API v5+.

Deprecated ​

These features still work for now, but will be removed in the future.

  • Server info page:
    • The indices object. Use corpora instead.
    • The top-level fieldInfo object. Instead, use the top-level pidField to find the persistent identifier field. For other special fields, you still have to use fieldInfo, but that will move to custom in API v5.
  • Document info page (/docs/DOC_PID) and results pages: metadataFieldDisplayNames, metadataFieldGroups and docFields are deprecated. This information can be found on the corpus info page, so it should be retrieved from there once.
  • Doc info on results pages and document info page: lengthInTokens is deprecated; use the first object in the tokenCounts array instead, which gives the tokenCount for the main annotated field.
  • Search operations:
    • the wordsaroundhit parameter (use context instead)
    • sort/group properties wordleft,wordright. Use before/after instead with 1 as the number of tokens, e.g. before:lemma:i:1 instead of wordleft:lemma:i.
    • The captureGroups response key. Use matchInfos instead.
  • The old /CORPUSNAME/... endpoints. Use the new /corpora/CORPUSNAME/... endpoints (that respond with API v5 responses) instead.

API support roadmap ​

This is how we intend to evolve BlackLab Server and Frontend with respect to API version support:

  • [x] BlackLab v4.x
    • [x] add API v4 (adds endpoints, transitional; default API)
    • [x] add API v5 experimental (enforces exclusive use of new endpoints)
  • [x] BlackLab Frontend v4.x
    • [x] works with BlackLab 4.x, uses API v5
  • [ ] BlackLab v5.0:
    • [x] API v5 is the default.
    • [x] API v4 is still supported but considered deprecated.
    • [x] API v3 was removed.
  • [ ] BlackLab Frontend v5.0:
    • [ ] works with BlackLab 4/5/6, uses API v5
  • [ ] BlackLab v6.0:
    • [ ] only support API v5.

Apache license 2.0