API for accessing articles from NDLA
Creates, updates and returns an Article
. Implements Elasticsearch for search within the article database.
To interact with the api, you need valid security credentials; see Access Tokens usage.
To write data to the api, you need write role access.
It also has as internal import routines for importing data from the old system to this database. There are a number of cleaning and
reporting services pertaining to the import which are only available for internal admin services.
The application can be configured by specifying several parameters as environment variables. See src/main/scala/no/ndla/articleapi/ArticleApiProperties.scala
for full list.
The endpoint GET /article-api/v2/articles/<id>
will fetch a json-object containing the article in the selected language.
The article body contained in this json-object consists of a strict subset of permitted HTML tags. It may also contain a special tag, <embed>
,
which is used to refer to content located in other APIs (including, but not limited to images, audio, video and H5P).
Some example usages of the embed tag:
<embed data-resource="external" data-url="https://youtu.be/7ZVyNjKSr0M" data-id="0" />
refers content from an external source (data-resource). In this case Youtube.data-url
is the url where the resource can be found, data-id
is an embed tag-identifier used to identify unique embeds in this article and is located in every embed tag.<embed data-align="" data-alt="Fyrlykt med hav og horisont" data-caption="" data-resource="image" data-size="fullbredde" data-id="1" data-url="http://image-api-url/image-api/v1/images/179" />
data-resource
) located in the image API, along with alignment info (data-align
), alternative text (data-alt
),data-caption
), intended display size in the article (data-size
), the unique embed tag-identifier (data-id
) and the url where image metadata can be found (data-url
).In order to display the article in its intended form all these embed-tags needs to be parsed and replaced with the content from its respectable source.
The article converter implements the logic needed to do this.
For a more detailed documentation of the API, please refer to the API documentation (Staging: API documentation).
Whenever an article is created or updated a validation of the content itself is performed. This is to ensure that only accepted tags and attributes are
used.
A list of permitted HTML/MathML tags and attributes are specified in the repo validation in the files src/main/resources/html-rules.json
and src/main/resources/mathml-rules.json
.
The tags
section defines permitted tags without attributes. The attributes
section defines tags with a list of permitted attributes.
Extra validation is performed on the <embed>
tag: based on the data-resource
attribute a different set of required attributes must also be present.
These rules are defined in src/main/resources/embed-tag-rules.json
in validation-repo. Should any attribute other than those in the required list be present,
they will be stripped before validation (this step is only performed on <embed>
tags).
When an article is fetched with the GET
API endpoint, the api will add a data-url
attribute on every <embed>
tag which also contains a data-resource_id
attribute.
A data-id
attribute is appended to each <embed>
tag.
The embed tag contains a set of attributes which define what content should be inserted. The list below provides an explaination of each recognized attribute.
Optional attribute groups are defined in the validatin library here.
Every attribute in an attribute group must be specified. Otherwise validation will fail.
The following attribute groups exists:
data-open-in
: Can only be used for content embed-tagsdata-upper-left-x
, data-upper-left-y
, data-lower-right-x
, data-lower-right-y
: Can only be used for image embed-tagsdata-focal-x
, data-focal-y
: Can only be used for image embed-tagsdata-title
: Can only be used for code-block embed-tags. Specifies title of code-blockdata-display
: Can only be used with file. Used to specify inline display of PDF-files. The following tags may contain extra attributes which conveys information about how they should be displayed
ol
aside
embed
resource=conceptCompile: sbt compile
Run tests: sbt test
Run pact provider verification tests: sbt “pact:testOnly — -n PactProviderTest”
Create Docker Image: sbt docker