<<

NAME

Koha::REST::Plugin::Objects

API

Helper methods

objects.find

    my $patrons_rs = Koha::Patrons->new;
    my $patrons = $c->objects->find( $patrons_rs, $id );
    . . .
    return $c->render({ status => 200, openapi => $patron });

Performs a database search using given Koha::Objects object and the $id.

Returns undef if no object is found or the API representation of the requested object including any embeds specified in the request.

objects.find_rs

    my $patrons_rs = Koha::Patrons->new;
    my $patron_rs = $c->objects->find_rs( $patrons_rs, $id );
    . . .
    return $c->render({ status => 200, openapi => $patron_rs->to_api });

Returns the passed Koha::Object result filtered to the passed $id and with any embeds requested by the api applied.

The result object can then be used for further processing.

objects.search

    my $patrons_rs = Koha::Patrons->new;
    my $patrons = $c->objects->search( $patrons_rs );
    . . .
    return $c->render({ status => 200, openapi => $patrons });

Performs a database search using given Koha::Objects object with any api query parameters applied.

Returns an arrayref of API representations of the requested objects including any embeds specified in the request.

Warning: this helper adds pagination headers to the calling controller, and thus shouldn't be called twice in it.

objects.search_rs

    my $patrons_object = Koha::Patrons->new;
    my $patrons_rs = $c->objects->search_rs( $patrons_object [, $query_fixers ] );
    . . .
    return $c->render({ status => 200, openapi => $patrons_rs->to_api });

Returns the passed Koha::Objects resultset filtered as requested by the api query parameters and with requested embeds applied.

The optional $query_fixers parameter is expected to be a reference to a list of function references. This functions need to accept two parameters: ( $query, $no_quotes ).

The $query is a string to be adapted. A modified version will be returned. The $no_quotes parameter controls if quotes need to be added for matching inside the string. Quoting should be used by default, for replacing JSON keys e.g "biblio.isbn" would match and biblio.isbn wouldn't.

Warning: this helper stashes base values for the pagination headers to the calling controller, and thus shouldn't be called twice in it.

objects.to_api

    my $patrons_rs = Koha::Patrons->new;
    my $api_representation = $c->objects->to_api( $patrons_rs );

Returns the API representation of the passed resultset.

<<