Skip to content

Commit

Permalink
Return API v2 responses in Turtle and RDF/XML (#851)
Browse files Browse the repository at this point in the history
* feature (webapi): Start implementing HTTP content negotation in API v2.

* fix (docs): Fix docs build error on Travis.

* feature (webapi): Add support for returning API v2 responses in Turtle.

* fix (webapi): Fix deployment issues #853, #855.

* fix (webapi): Use UTF-8 to read file resources.

* feature (webapi): Use @graph instead of hasOntologies, etc. (ongoing)

* feature (webapi): Replace hasOntologies with JSON-LD graph.

* test (webapi): Add tests for serving ontologies in Turtle.

* refactor (webapi): Refactor handling of RDF media types.

- Use JSON-LD content type for JSON-LD responses.

* feature (webapi): Return ontology responses in RDF/XML.

- Simplify R2R ontology test code.
- Make it easier to regenerate expected response files.

* feature (webapi): Don't bother trying to return HTML.

* refactor (webapi): Move some methods into JsonLDObject.

* feature (webapi): Change resource responses to use JSON-LD graphs.

* feature (webapi): Return resources in Turtle and RDF/XML.

- Add datatypes where needed in responses in the simple schema.

* docs (webapi): Update docs and release notes.

* feature (webapi): Use simple prefix labels in responses when possible.

* docs (knora-ontologies): Fix mistakes in salsah-gui doc.

* tests (add test data)

* test (webapi): Update tests to reflect new test data.

* feature (webapi): Support q values in content negotiation.

- Rename RouteUtilV2.runJsonRoute -> runRdfRoute.

* fix (webapi): Store project shortcodes in upper case (#865).

* fix (webapi): Don't treat application/xml as an RDF media type, to avoid returning it to browsers.

* style (webapi): Fix typos.

* refactor (webapi): Remove unnecessary method type parameter.

* style (webapi): Improve comments.

* refactor (webapi): Remove unnecessary pattern match.

* test (webapi): Update tests.

- Add tests for requesting lists in Turtle and RDF/XML.
- Update sample resource responses in resourcesResponses.ts.

* fix (fix test functions)

* test (webapi): Try increasing timeout to prevent Travis test failures.

* fix (webapi): Trim whitespace from elements of Accept header.

* fix (webapi): Fix exception.
  • Loading branch information
Benjamin Geer authored May 30, 2018
1 parent f7bc611 commit 75152d5
Show file tree
Hide file tree
Showing 163 changed files with 37,791 additions and 17,415 deletions.
1 change: 0 additions & 1 deletion docs/src/api-v2/MappingFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ export module MappingFormats {


}

27 changes: 3 additions & 24 deletions docs/src/api-v2/ResourcesResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,10 @@ export module ResourcesResponse {
*
*/
export interface ResourcesSequence {
/**
* ResourcesSequence response format corresponds to http://schema.org/ItemList
*/
"@type": "http://schema.org/ItemList";

/**
* A resource or a sequence of resources (instances).
*/
"http://schema.org/itemListElement": Resource | Array<Resource>;

/**
* Length of the sequence of resources.
*/
"http://schema.org/numberOfItems": number;

"@graph": Array<Resource>;
}
}

Expand Down Expand Up @@ -127,23 +116,13 @@ export module ResourcesResponse {
*
*/
export interface ResourcesSequence {
/**
* ResourcesSequence response format corresponds to http://schema.org/ItemList
*/
"@type": "http://schema.org/ItemList";

/**
* A resource or a sequence of resources (instances).
*/
"http://schema.org/itemListElement": Resource | Array<Resource>;

/**
* Length of the sequence of resources.
*/
"http://schema.org/numberOfItems": number;
"@graph": Array<Resource>;

}

}

}
}
2,451 changes: 1,062 additions & 1,389 deletions docs/src/api-v2/samples/resourcesResponses.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/src/paradox/00-release-notes/v1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ New features:

- Resources can be returned in the simple ontology schema (#833).
- Text values can specify the language of the text (#819).
- Responses can be returned in Turtle and RDF/XML (#851).

Bugfixes:
---------
Expand Down
17 changes: 8 additions & 9 deletions docs/src/paradox/02-knora-ontologies/salsah-gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ The attributes used with each GUI element are described below under
`guiAttributeDefinition`

: Used only in the `salsah-gui` ontology itself, as a predicate
attached to instances of `Guielement` (see
[salsah-gui-individuals]{role="ref"}), to specify the attributes
that can be given as objects of `guiAttribute` when a given
attached to instances of `Guielement` (see @ref:[Individuals](#individuals)),
to specify the attributes that can be given as objects of `guiAttribute` when a given
`Guielement`. is used. The objects of this predicate are written in
a DSL with the following syntax:

Expand Down Expand Up @@ -136,31 +135,31 @@ identifier = letter , { letter } ;
`List`

: A GUI element for selecting an item in a hierarchical list (see
[knora-base-list-value]{role="ref"}). A property definition that
@ref:[ListValue](knora-base.md#listvalue)). A property definition that
uses this element must also contain this `guiAttribute` predicate:

- `"hlist=<LIST_IRI>"`, where `LIST_IRI` is the IRI of a
`knora-base:ListNode`.
`knora-base:ListNode` that is the root node of a hierarchical list.

`Pulldown`

: A GUI element for selecting an item in a flat list (see
[knora-base-list-value]{role="ref"}) using a pull-down menu. A
@ref:[ListValue](knora-base.md#listvalue)) using a pull-down menu. A
property definition that uses this element must also contain this
`guiAttribute` predicate:

- `"hlist=<LIST_IRI>"`, where `LIST_IRI` is the IRI of a
`knora-base:ListNode`.
`knora-base:ListNode` that is the root node of a hierarchical list.

`Radio`

: A GUI element for selecting an item in a flat list (see
[knora-base-list-value]{role="ref"}) using radio buttons. A property
@ref:[ListValue](knora-base.md#listvalue)) using radio buttons. A property
definition that uses this element must also contain this
`guiAttribute` predicate:

- `"hlist=<LIST_IRI>"`, where `LIST_IRI` is the IRI of a
`knora-base:ListNode`.
`knora-base:ListNode` that is the root node of a hierarchical list.

`Richtext`

Expand Down
1 change: 0 additions & 1 deletion docs/src/paradox/03-webapi/api-v2/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- [XML to Standoff Mapping](xml-to-standoff-mapping.md)
- [KnarQL: Knora Query Language](query-language.md)
- [Querying, Creating, and Updating Ontologies](ontology-information.md)
- [Response Formats](response-formats.md)

@@@
45 changes: 23 additions & 22 deletions docs/src/paradox/03-webapi/api-v2/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public
License along with Knora. If not, see <http://www.gnu.org/licenses/>.
-->

# Introduction: Using API V2
# Introduction: Using API v2

@@toc

Expand All @@ -32,13 +32,28 @@ format that is consistent and hence easier to use for a client.
Please note that V2 is still in development. We do not yet recommend
using it on productive systems.

## V2 Path Segment
## API v2 Path Segment

Every request to API V1 includes `v2` as a path segment, e.g.
Every request to API v2 includes `v2` as a path segment, e.g.
`http://host/v2/resources/http%3A%2F%2Frdfh.ch%2Fc5058f3a`.
Accordingly, requests using any other version of the API will require
another path segment.

## Response Formats

All API v2 responses can be returned in
[JSON-LD](https://json-ld.org/spec/latest/json-ld/),
[Turtle](https://www.w3.org/TR/turtle/),
or [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/), using
@extref[HTTP content negotiation](rfc:7231#section-5.3.2). The client
can request these formats using the following MIME types:

| Format | MIME Type |
|---------|-----------------------|
| JSON-LD | `application/ld+json` |
| Turtle | `text/turtle` |
| RDF/XML | `application/rdf+xml` |

## JSON-LD

Our preferred format for data exchange is
Expand All @@ -53,36 +68,22 @@ RDF types (e.g. XSD datatypes) or more complex types whose IRIs can be
dereferenced to get more information about their structure.

At the same time, JSON-LD responses are relatively easy for software
developers to work with. Items in a response can have human-readable
names, which can nevertheless be expanded to full IRIs. Also, while a
format such as [Turtle](https://www.w3.org/TR/turtle/) just provides a
developers to work with, and are more concise and easier to read than
the equivalent XML. Items in a response can have human-readable names,
which can nevertheless be expanded to full IRIs. Also, while a format such as
[Turtle](https://www.w3.org/TR/turtle/) just provides a
set of RDF triples, an equivalent JSON-LD response can explicitly
provide data in a hierarchical structure, with objects nested inside
other objects.

We designed the V2 routes in a way that would also allow for the usage
of other formats such as XML. We plan to implement support for XML once
the implementation of JSON-LD is completed. The client will be able to
use content negotiation to specify the preferred exchange format.

## Support of schema.org Entities

Some entities defined in [schema.org](http://www.schema.org) are used in
API v2 responses (e.g., `ResourcesSequence`, see
@ref:[Response Formats](response-formats.md)). For example,
`knora-api:Resource` is declared to be a subclass of
`http://schema.org/Thing`, so we can use a `knora-api:Resource` or
any of its subclasses where `http://schema.org` requires a
`http://schema.org/Thing`.

## Knora IRIs

Resources and entities are identified by IRIs. The format of these IRIs
is explained in @ref:[Knora IRIs](knora-iris.md).

## API Schema

Knora API V2 offers the query and response format in a complex schema
Knora API v2 offers the query and response format in a complex schema
and a simple one. The main difference is that the complex schema exposes
the complexity of value objects, while the simple version does not. A
client that needs to edit values must use the complex schema in order to
Expand Down
Loading

0 comments on commit 75152d5

Please sign in to comment.