NAME

Whelk::Role::Resource - Role for Whelk API resources

SYNOPSIS

package My::Custom::Resource;

use Kelp::Base 'My::Custom::Controller';
use Role::Tiny::With;

with qw(WhelK::Role::Resource);

# required by the role
sub api
{
	my ($self) = @_;

	# implement the api
	...;
}

DESCRIPTION

This is a role which implements Whelk resources. It must be applied to a Kelp controller which is meant to be used as a resource for Whelk. Whelk::Resource is such controller, and is also a base controller for Whelk - there is no need to manually consume the role if you are extending it. If you write your own Kelp application which uses Whelk, you most certainly want to only apply it in a couple of your controllers and not the main controller.

This role requires you to implement api method - it will not apply if this prerequisite is not met. It also requires context attribute to be present, which is also a requirement made by Kelp.

Whelk will reject any resources defined in its resources configuration field which do not consume this role.

METHODS

This role implements just a couple of helpful methods which you may use in api method and your route handler methods.

request_body

my $body = $self->request_body;

A helper which returns the request body saved by the wrapper in stash key request.

add_endpoint

Standard Whelk method to add endpoints, discussed at length in "Adding endpoints" in Whelk::Manual.