Package DE_EPAGES::WebService::API::Resource::BaseResource
Base class for REST resources.
Functions
- chooseAction
- chooseVariant
- codecByContentType
- href
- match
- new
- params
- producedContentTypes
- requestCodec
- requestContext
chooseAction
Uses HTTP content negotiation to find the appropriate content variant and the corresponding implementation. Throws a NotAcceptable error if the request cannot be served.
Syntax |
($ActionName, $ResponseCodec) = $Resource->chooseAction($Request); |
Input |
|
Return |
|
chooseVariant
Uses HTTP content negotiation to find the appropriate content variant and the corresponding implementation. Throws a NotAcceptable error if the request cannot be served.
Syntax |
$aVariant = $Resource->chooseVariant($Request); |
Input |
|
Return |
|
codecByContentType
Returns a suitable decoder/encoder object for a message with the given Content-Type. Returns undefined if there is no suitable codec.
Syntax |
$Codec = $Resource->codecByContentType($ContentType); |
Example |
if ($RequestCodec) { $Data = $RequestCodec->decode($Request); } |
Input |
|
Return |
|
href
build an reference link based on API url and ressource related parameters
Syntax |
$href = $Package->href($APIBaseURL, @Params); |
Example |
{ rel => 'variations', href => DE_EPAGES::Product::API::Resource::ProductVariation->href($APIBaseURL, $SuperProduct->guid), } |
Input |
|
Return |
|
match
Tests if the resource can handle the request. If no, returns an empty list. If yes, returns a defined value. In some cases this value can be interpreted as object identifier for the actual resource.
Syntax |
$Match = $Resource->match($Request); |
Example |
$Match = $Resource->match($Request); if (defined $Match) { my $hRequestContext = $Resource->requestContext($Site, $Match, $Request); } |
Input |
|
Return |
|
new
Create a new REST resource object.
Syntax |
$Resource = DE_EPAGES::WebService::API::Resource::BaseResource->new(%Options); |
Input |
|
Return |
|
params
Returns the parameters for the action function.
Syntax |
$hRequestContext = $Resource->params($ActionName, $Match, $Request); |
Input |
|
Return |
|
producedContentTypes
Returns the available result content types of the resource for a given request method. Returns undefined if the method does not produce any content.
Syntax |
$aVariants = $Resource->producedContentTypes( $RequestMethod ); |
Input |
|
Return |
|
requestCodec
Returns a suitable decoder object to deserialze the request body. Returns undefined if the request does not have a Content-Type header or if there is no suitable decoder for the given Content-Type.
Syntax |
$RequestCodec = $Resource->requestCodec($Request); |
Example |
if ($RequestCodec) { $Data = $RequestCodec->decode($Request); } |
Input |
|
Return |
|
requestContext
Tests if the resource can handle the request. If no, returns an empty list. If yes, returns the function to execute the request.
Syntax |
$hRequestContext = $Resource->requestContext($Site, $Match, $Request); |
Input |
|
Return |
|