Endpoints are the HTTP entry points which are accessible on your API. In sapi-nt, endpoints are designed to be RESTful whenever possible. A single endpoint is defined by its URL path, and may serve a variety of data in multiple formats.
Endpoint specs are characterised by the following type values:
| Type | Meaning |
|---|---|
endpoint.item |
An endpoint serving a single resource whose URI corresponds to the requested URI. |
endpoint.list |
An endpoint serving a collection of resources. |
endpoint.template |
An endpoint serving the results of a specific parameterised SPARQL query. |
endpoint.forward |
An endpoint which delegates requests to another endpoint. |
item |
Deprecated - Please use endpoint.item. |
list |
Deprecated - Please use endpoint.list. |
template |
Deprecated - Please use endpoint.template. |
forward |
Deprecated - Please use endpoint.forward. |
You can define an endpoint whose name value is the value of the sapi-nt.api.defaultEndpointName application property
to declare it as the default endpoint.
If you do, requests that cannot be mapped to any particular endpoint will be directed to it.
You can also declare time series endpoints which accept requests for data stored in a Cassandra database. Integrating sapi-nt with Cassandra is documented here.
All endpoint specs have a url property, whose value is a URL path on which the endpoint is located.
This path can be relative to the domain of your application, in which case it must start with the context path of the application.
Otherwise, sapi-nt will infer that the path is relative to the context path.
For example, if the context path is /api, then the endpoint url values /api/station and /station are equivalent.
You can define endpoints which accept requests to exact URL paths, or those matching a certain pattern.
The variable parts of the path pattern are known as path parameters, and can be written as {pathParam}.
Path parameters which are written in this way will be treated as request parameters. For example, you can use this method to apply filter parameters to requests that target a certain endpoint, although this works the same way for any kind of request parameter. See the documentation for a full explanation of request parameters.
To define an endpoint which reads a request parameter onLine from the requested URL, you can set the following url value in the endpoint spec:
url: /underground/{onLine}/station
When the path parameter is defined in this way, it must be handled by the sapi-nt application.
If it is not an acceptable request parameter for that endpoint, sapi-nt will return a 400 Bad Request response.
However, you may need to define an endpoint which answers all requests matching a certain path pattern,
but does not treat the path parameter as a request paramater.
You can do this by prepending __ onto the path parameter in the endpoint spec’s URL path, eg. {__pathParam}.
This indicates to sapi-nt that the parameter should not be treated as a request parameter, and it will be ignored.
This method is typically used to define item endpoints, which accept all requests with a certain path pattern, and return the resource whose URI corresponds to the full request URL.
To define an item endpoint which returns resources whose URIs match a certain pattern, you can set the following url value in the endpoint spec:
type: endpoint.item
url: /underground/station/{__id}
Item, list and template endpoints can define views, which are branching, tree-like structures that determine which property paths, relative to the root resources, will be exposed by the API.
Endpoint specs which support views can have the following properties:
| Property | Meaning |
|---|---|
view |
The name of a view spec to use by default, or an inline view definition. |
views |
A map of view names (which can be requested with the _view parameter) to named or inline view specs. |
An endpoint can have a single view (given by the view property of the endpoint spec), which will be applied to every request,
or multiple views which the API user can select from by supplying a _view query parameter (given by the views property of the endpoint spec).
The value of the views property should be a nested map of key-view pairs.
The keys identify each view in the context of the endpoint, and can be different from the name of the view itself.
API users can request the view by setting the _view query parameter of their requests to that key.
The view which has the key default will be applied to any request that is handled by the endpoint which doesn’t specify a view.
The views can be written as a string, referring to the unique name of a view spec defined elsewhere in your application’s spec directory,
or as inline view definitions, following the same YAML structure as described in the view spec documentation.
A fragment of an endpoint spec with a default and a compact view, where the view spec compactView is defined elsewhere:
views :
default :
- "rdfs:label"
- "skos:notation"
- "eg:group"
- prop : "skos:narrower"
optional : true
nested :
- "rdfs:label"
- "skos:notation"
- "eg:group"
compact : compactView
detail:
class: "def-pa:ProtectedArea"
projection: "*,narrower.*,group.*"
A fragment of an endpoint spec with a single view:
view :
- "rdfs:label"
- "skos:notation"
- prop : "skos:narrower"
optional : true
nested :
- "rdfs:label"
- "skos:notation"
If batch processing is enabled for your sapi-nt application,
you can enable it for list and template endpoints by setting the enabled property on the nested batch property of the spec
to true.
See the documentation for how to configure individual endpoints.
A fragment of an endpoint spec with batch processing enabled:
type: endpoint.list
batch:
enabled: true
Sapi-nt can be configured to automatically generate documentation for your API. See the documentation for how to use this feature. All endpoint specs can have the following documentary properties:
| Property | Meaning |
|---|---|
comment |
A brief description of the endpoint. |
example |
A working example of a URL path that will be handled by the endpoint. This is useful for endpoints with path parameters. By default this is the value of url. |
pathParameters |
A list of nested documentary objects for the endpoint’s path parameters. |
documentationParameters |
A list of nested documentary objects for any significant or frequently used query parameters. Standard parameters are documented by default. |
The nested documentary objects for path and query parameters can have the following properties:
| Property | Meaning |
|---|---|
description |
A brief description of the parameter. |
type |
The URI of the expected datatype of the parameter values. |
required |
If true, the parameter must be supplied for the request to be accepted. Defaults to false for query parameters, true for path. |
pattern |
A regular expression to which values of the parameter are expected to conform. Currently has no effect. |
rangePattern |
Deprecated - Please use pattern. |
Setting the required and pattern properties only affects the generated documentation does not necessarily mean that they will be enforced.
You can enforce these rules on endpoints by configuring request validators.
name : station
type : endpoint.item
url : /underground/station/{__id}
description: "Details of a single station on the underground network."
example : /underground/station/ActonTown
pathParameters:
__id:
description: ID of the station.
type: xsd:string
pattern: /([a-Z])*/
All endpoint specs have the standard name and type properties, as well as a url property (see above section on URL paths).
Item, list and template endpoints can all have the following properties:
| Property | Meaning |
|---|---|
dataSource |
The name of the data source to query against. If not set, uses the default spec. |
datasource |
Deprecated - Please use dataSource. |
engine |
The name of the processing engine to use. If not set, uses the standard sapi-nt engine. |
template |
Name of a Pebble template to render for HTML responses. If not set, uses the application default for the endpoint type. |
maxAge |
The maximum age, in seconds, to include in the cache control headers for each response. If not set, the header will not be set. |
aliases |
A mapping of aliases of request parameters to the name of the parameter they are aliasing. |
contentTypes |
Array of content types that can be returned by the endpoint. If not set, all of the content types supported by sapi-nt can be returned. |
geoFetchSupported |
If true, a geo fetch query is supported. Otherwise, it is not. Defaults to false. |
Item endpoints, having a type of endpoint.item, serve information about individual resources.
Typically, a single item endpoint can emit all resources under a particular URL path.
An item endpoint spec can have the following properties:
| Property | Meaning | Default |
|---|---|---|
isDescribe |
If true, issues DESCRIBE queries against the data source. Otherwise, issues SELECT queries. | true |
You can configure the default values for some of these properties by setting the application properties under sapi-nt.defaults.spec.endpoint.item.
name : station.item
type : endpoint.item
url : /underground/station/{__id}
isDescribe: true
Unlike other endpoints, item endpoints can perform SPARQL describe queries on resources by setting the isDescribe property to true.
This is useful for exposing the main properties of a generic resource without having to define a specific view.
As such, it may be useful to set an item endpoint, with describe queries enabled, as the default endpoint for your API, since it will attempt to identify any request URI with the URI of a resource in the data set.
You can define an item endpoint with one or more views and describe queries enabled. This endpoint will handle requests by performing a describe query on every element of the view, and coalescing the resulting graph in the response.
When responding to a request sent to an item endpoint, sapi-nt uses the URL of the request and the base URI of the application to locate the corresponding resource. The resource URI is inferred by replacing the origin and context path of the requested URL with the base URI.
For a sapi-nt application with a base URI of http://example.org/transport, a context path of /api, running on http://localhost:8080,
with an item endpoint spec:
type: endpoint.item
url: /api/station/{__id}
A request sent to:
http://localhost:8080/api/station/ActonTown
Will attempt to return information about the resource with URI:
http://example.org/transport/station/ActonTown
List endpoints, having a type of endpoint.list, serve collections of resources, usually all belonging to a particular
classification, such as having the same rdf:type or belonging to the same concept scheme.
A list endpoint spec can have the following properties:
| Property | Meaning | Default |
|---|---|---|
query |
Either a fragment of the WHERE clause of a SPARQL query specifying the root resources associated with this endpoint, or a nested configuration object. | |
softLimit |
Default limit on the number of root resources that can be returned when no limit is given by the request. | |
hardLimit |
A hard limit on the maximum number of root resources that can be returned from this endpoint in one response. | |
distinct |
Set to true to add a DISTINCT qualifier to the inner query. | false |
filterDistinct |
If true, text search queries will add a DISTINCT qualifier to the inner query. Otherwise, they will not. | true |
unionStyle |
If true, issues “union style” SPARQL queries, which have improved performance over large views. Otherwise, issues “optional style” queries. | false |
geoParameter |
A parameter used to bind geo filter to the query. | |
geoFilters |
A list of supported geo filters. | |
textSearch |
Text search configuration. See documentation below. |
You can configure the default values of some of these properties by setting the application properties under sapi-nt.defaults.spec.endpoint.list.
Sapi-nt dynamically generates the SPARQL queries that are issued by list endpoints, based on the structure of the associated view and the query parameters supplied by the request. As such, list endpoints are able to support many of the standard request parameters, including filters on property values. See the documentation for more information.
name : station
type : endpoint.list
url : /underground/station
query : "?id a metro:UndergroundStation ."
textSearch: true
geoFilters:
- CircleFilter
- PolygonFilter
views :
default :
class: metro:UndergroundStation
projection: "label,onLine(label),lat,long"
compact : compactView
contentTypes:
- "application/json"
- "text/html"
The query property on a list endpoint spec determines the base query for locating the root resources associated with the endpoint.
It can be provided as a fragment of a SPARQL WHERE clause, using the variable ?id to denote the root binding, or as a nested configuration object.
When a nested configuration object is given, its key-value pairs denote a set of filters to apply to the data set. The keys denote the RDF properties to which to apply the filter, and the corresponding values are the values to filter on. Keys should be given as full or compact URIs (using the prefix mapping defined in the default model). Values can also be given as compact URIs in the same way. Their type will be inferred automatically.
Since it is often necessary to define this base query as a filter on rdf:type, you can simply use the key type to denote rdf:type.
Both SPARQL fragments and the property values of nested configuration objects can use a variable binding syntax, ${variable}
to denote that the value should be taken from the request parameter with the same name.
If any variables in a query definition are not bound by the request, the request will fail with a 400 Bad Request response.
A list endpoint spec with a raw SPARQL query definition:
name : listQueryFragment
type : endpoint.list
url : /example/path
query : "?id a skos:Concept ."
A list endpoint spec with a nested query definition:
name : listQueryConfig
type : endpoint.list
url : /example/path
query :
type: "skos:Concept"
The textSearch property on an list endpoint spec determines whether users will be able to request a search on the
Lucene text index of the underlying store.
See the request parameters documentation
for more detail.
The textSearch configuration can be given in the following forms:
| Form | Usage | Default |
|---|---|---|
| Boolean | true to enable text search, false to disable. |
false |
| String | The name of the property on which to apply the text search. id denotes the root item. |
id |
| Object | A nested configuration object for more specific configuration options. |
If any form is given except for false, then text search will be enabled.
The nested configuration object can have the following properties:
| Property | Meaning | Default |
|---|---|---|
path |
The .-separated property path to treat as the subject of the text search. id denotes the root item. |
id |
fuzzy |
true to enable fuzzy text searches, false to disable. Alternatively, a nested configuration object. |
true |
limit |
A limit to apply to the number of results that the Jena text query can return in SPARQL. You can support text searches on larger data sets by increasing this value. | 10000 |
The fuzzy property can given as a nested object with the following properties:
| Property | Meaning | Default |
|---|---|---|
enabled |
true to enable fuzzy text searches, false to disable. |
true |
similarity |
A decimal between 0 and 1 which determines the similarity required for a term to match the requested search parameter. 0 is the least similarity, 1 is the most. | 0.5 |
See the Lucene documentation for more information about fuzzy search options.
name : listTest
type : endpoint.list
url : /test/path
query : "?id a skos:Concept ."
textSearch:
root: id
fuzzy:
enabled: true
similarity: 0.7
limit: 50000
Template endpoints, having a type of endpoint.template, serve the results of specific parameterised SPARQL queries.
You can use them to issue queries which don’t conform to the dynamically generated structure of list endpoints, such as aggregation queries.
However, this means that many standard request parameters such as filters and text searches are not supported by template endpoints.
The template for the SPARQL query issued by a template endpoint is given by the query property of the spec.
Unlike list endpoints, this must be a complete and valid SPARQL query, including namespace prefix mappings.
Similarly to list endpoints, template queries can contain bindable variables, denoted by %{variable},
which will take values from the request parameters of the same name.
If any variables in a template query are not bound by the request, the request will fail with a 400 Bad Request response.
A template endpoint spec can have the following properties:
| Property | Meaning |
|---|---|
query |
The parameterised SPARQL query for the endpoint. |
Forward endpoints, having a type of endpoint.forward, delegate requests to other endpoints.
Forward endpoints are unique in that they don’t define any behaviour of their own,
but simply provide alternative access points to other endpoints.
However, the main usage of forward endpoints is to supply request parameters given by their URL paths to other endpoints, since path parameters are retained on the request handled by the delegated endpoint. For example, you can create a forward endpoint which entails a filter parameter on another endpoint.
A forward endpoint spec can have the following properties:
| Property | Meaning |
|---|---|
forwardTo |
The name of the endpoint spec to which to delegate. |
To define a forward endpoint that supplies the onLine filter parameter to a list endpoint named station,
you can use the following specs:
type: endpoint.list
name: station
url: /underground/station
view:
- prop: rdfs:label
- prop: metro:onLine
name: onLine
valueBase: "lu-l:":
---
type: endpoint.forward
name: station.line
url: /underground/{onLine}/station
forwardTo: station