How to Add an API v1 Route
Write SPARQL templates
Add any SPARQL templates you need to
using the Twirl template
Write Responder Request and Response Messages
Add a file to the
package, containing case classes for your responder's request and
response messages. Add a trait that the responder's request messages
extend. Each request message type should contain a
Response message classes that represent a complete API response must
KnoraResponseV1, and must therefore have a
that converts the response message to a JSON AST using
Write a Responder
Write a class that extends
and add it to the
Give your responder a
receive(msg: YourCustomType) method that handles each of your
request message types by generating a
Future containing a response message.
See Triplestore Access for details of how to access the triplestore in your responder.
Add the path of your responder to the
org.knora.webapi.responders package object,
and add code to
ResponderManager to instantiate an object for your responder class.
Then add a
case to the
receive method in
ResponderManager, to match
messages that extend your request message trait, and pass them to the responder's
receive method. The responder's resulting
Future must be passed to the
See Futures with Akka and
Error Handling for details.
Write a Route
Add a class to the
org.knora.webapi.routing.v1 package for your
route, using the Akka HTTP Routing DSL.
See the routes in that package for examples. Typically, each route
route will construct a responder request message and pass it to
RouteUtilV1.runRdfRouteWithFuture to handle the request.
Finally, add your
knoraApiPath function to the
KnoraService. Any exception thrown inside the route will
be handled by the
KnoraExceptionHandler, so that the correct client
response (including the HTTP status code) will be returned.