To implement your own server-side inbox to receive and process COAR Notify notifications, this library provides some framework-agnostic supporting classes to help you get started.
The architecture this supports for implementations is as follows:
Your web framework provides the routes and the handler for incoming requests. The raw notification body can then be passed to the coarnotify\server\COARNotifyServer
class to handle parsing and validation of the notification. Once this is done, it is passed on to your implementation of the coarnotify\server\COARNotifyServiceBinding
class. This carries out the actions required for the notification and then responds with a coarnotify\server\COARNotifyReceipt
object, which makes its way back to your web framework to be returned to the client in whatever way is most appropriate.
Built into this library is a test server which demonstrates a simple implementation of a server.
This example uses the Slim web framework and provides an inbox
route as the target for notifications.
To process a notification, you need to implement a custom service binding class that extends coarnotify\server\COARNotifyServiceBinding
. This class receives the notification and processes it.
The notification received by the service binding is a full COAR Notify model object.
This example implementation receives the notification and writes it to a file in a configured directory. It then returns a location and a CREATED
status.
You can now pass the custom service binding class to the COAR Notify server class on construction.
inbox
RouteFinally, extend the inbox
route to use the COARNotifyServer::receive
method to process the notification and handle the response to the user.
Using this approach, the web layer is responsible only for reading the incoming request and returning a suitable response to the user. The COAR server handles the business of parsing and validating the content and then passes the request on to a web-independent controller you have supplied to process the notification.