The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Sloth::Method - The implementation of a single HTTP method on a resource

ATTRIBUTES

request_parsers

A Map[ContentType = Sloth::RequestParser].

This map defines a list of parsers that are able to parse the body of a HTTP request into a meaningful, but more importantly, common, set of input parameters.

If this is left undefined it is assumed that a body is not meant to be provided to the method, and that all necessary parameters can be derived from the URI query parameters and path parts.

request_data_validator

A Data::TreeValidator validator.

This takes the input from query parameters, path parts, and possibly the parsed request body, and validates it. It can optionally transform the data, and will finally return a set of clean input parameters which are passed to "execute".

process_request

    $self->process_request($request : Sloth::Request)

Process a Sloth::Request and possibly return a resource.

You usually won't need to override this method, as by default it does the boiler plate plumbing for you (checking the Accept header, trying to parse the body, etc). Most users will simply need to implement "execute".

METHODS

execute

    $self->execute($cleaned_parameters)

Required. Classes which consume this role must implement this method.

Executes the implemented HTTP method (for example a GET or DELETE operation) and optionally returns a resource to represent back to the user. Takes an object that represents the cleaned input parameters - a combination of path arguments, query paramaters and the parsed body (if there was one).

try_serialize

    $self->try_serialize($object)

If you are returning a custom Sloth::Response from your method body, you may still wish to serialize some data into the response body. By using try_serialize you will get correct handling of the Accept: header from the client.

AUTHOR

Oliver Charles

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Oliver Charles <sloth.cpan@ocharles.org.uk>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.