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:
parameters:
# default to API v4 while we plan our migration to API v5
api: 4On 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
indiceskey. Usecorporainstead. - Document info page (
/docs/DOC_PID) and results pages no longer includemetadataFieldDisplayNames,metadataFieldGroupsordocFields. 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
captureGroupsanymore. UsematchInfosinstead. - If you specify
subcorpussize=true(formerly calledincludetokencount),summarydoesn't include thetokensInMatchingDocumentskey anymore. This information is available under thesubcorpusSizekey.
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 specifyapi=4or 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 affectssummary/searchParams,docInfos,users[]in/sharingresponse. - 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.
- XML responses don't use dynamic values as element names anymore, but instead adopt a
- server, corpus, field info:
indexNamein corpus info has been replaced withcorpusName.indexNamewas dropped from the field info response.- Corpora, metadata and annotated field and annotations report certain properties (such as
displayName,description) inside acustomblock 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 specifycustom=true. - Document and token count have been grouped under a
countkey. A parallel corpus will also include adocVersionskey that gives the total number of document versions.annotatedFieldswill also include acountkey that gives the number of docs/tokens for that field.
- Results pages:
summaryhas been restructured to group related values together underparams,resultWindowandresultStats. Subkeys have been renamed for clarity.summary.paramsare 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/righthave been replaced withbefore/afterin the/hitsresponse. docInfosnow have ametadatasubobject instead of mixing metadata withmayViewandlengthInTokens.- When using
usecontent=orig, the value ofescapexmlfragmentnow defaults totrue, so XML fragments from the document will be escaped as CDATA. Set it tofalseto 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
versionInfoblock,blacklabVersionandblacklabBuildTimeare now spelled with a lowercasel, 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.
- Two keys were renamed to be more consistent: in the
- Annotated fields:
displayOrderwill no longer include internal annotations (e.g.punctand_relation, previously calledstarttag), 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; assume3.0if missing) - In addition to
indices, the newcorporakey was added that provides the same information in a slightly different format. You should usecorporainstead ofindicesfor future compatibility. - In addition to being reported under
fieldInfo,pidFieldis now also a top-level key. You should use this version of the key for future compatibility. (the other special fields infieldInfowill be moved tocustomin v5)
- New key added (
- Corpus info page:
mainAnnotatedFieldindicates 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
pattparameter may also be specified as a JSON query structure. This will be detected automatically, or you can setpattlangtojsonto make it explicit. - In the JSON response,
summarywill now include apatternobject containing: ajsonkey that giving the JSON query structure; abcqlkey giving the (re-)serialized pattern in BlackLab Corpus Query Language; afieldNamekey giving the search field, e.g."contents"; and amatchInfoskey 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-patternendpoint, see below). The XML response does not contain thejsonobject. - If you specify
subcorpussize=true(formerly calledincludetokencount),summarywill include asubcorpusSizekey 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 theannotatedFieldssubkey. - In addition to
captureGroups,matchInfoswill be reported that includes the same information as well as any inline tags and relations matched. You should use this instead ofcaptureGroupsfor future compatibility. before/afterare the new, preferred alternatives toleft/right,e.g. when sorting/grouping on context. Not all languages are LTR, so this makes more sense. Existing endpoints still useleft/rightin 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/wordrighthave been deprecated. Usebefore/afterwith 1 token instead. - Grouped results also include a
propertieskey that gives the values for the individual properties used for grouping. This is an alternative toidentityDisplay, which clients would sometimes have to parse to display it in their preferred way. contextis the new name for thewordsaroundhitparameter and supports more options (separate before/after, whole sentence, etc.)
- The
- Pages that list values for fields, tags, etc. now support the
limitvaluesparameter. This parameter defaults to200, 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-patternwas added that allows you to parse a CorpusQL or JSON query structure pattern without actually executing the search. - Field info will return
relationsblock containing all the spans ("inline tags") and relations indexed in the corpus. - Doc info on results pages and document info page: the new
tokenCountsarray gives token counts for all annotated fields. The first annotated field is the main one, which has the same value aslengthInTokens. - When using
usecontent=orig, you can now specifyescapexmlfragmentto control whether XML fragments are escaped as CDATA or not. This defaults tofalsefor API v4 and older, but will betruefor API v5+.
Deprecated
These features still work for now, but will be removed in the future.
- Server info page:
- The
indicesobject. Usecorporainstead. - The top-level
fieldInfoobject. Instead, use the top-levelpidFieldto find the persistent identifier field. For other special fields, you still have to usefieldInfo, but that will move tocustomin API v5.
- The
- Document info page (
/docs/DOC_PID) and results pages:metadataFieldDisplayNames,metadataFieldGroupsanddocFieldsare 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:
lengthInTokensis deprecated; use the first object in thetokenCountsarray instead, which gives thetokenCountfor the main annotated field. - Search operations:
- the
wordsaroundhitparameter (usecontextinstead) - sort/group properties
wordleft,wordright. Usebefore/afterinstead with1as the number of tokens, e.g.before:lemma:i:1instead ofwordleft:lemma:i. - The
captureGroupsresponse key. UsematchInfosinstead.
- the
- 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.