A Qualifier Example
resource schema
<@qualifier/schema
summary: 'The curl qualifier'
items: <
<@qualifier/schema/item
name: 'url'
summary: 'The end point of the web service'
defaultValue: 'https://meowfacts.herokuapp.com/'
mandatory: false()
>
<@qualifier/schema/item
name: 'type'
summary: 'The type of response json or text'
defaultValue: 'json'
mandatory: false()
>
>
>
end-resource
function main( curl )
try
set( 'request', httpRequest.create( pb.get( [curl], 'url' ) ) )
httpRequest.get( [request] )
if eq( httpRequest.responseStatusCode( [request] ), 200 )
switch pb.get( [curl], 'type' )
case 'text'
return <
status: 'ok'
reason: null()
details: httpRequest.responseBody( [request] )
>
case 'json'
return <
status: 'ok'
reason: null()
details: json.json2pb( httpRequest.responseBody( [request] ) )
>
end-switch
else
return <
status: 'error'
reason: 'Unexpected status code'
details: httpRequest.responseStatusCode( [request] )
>
end-if
catch
return <
status: 'error'
reason: error.firstMessage()
details: error.dump()
>
finally
if isNotNull( [request] )
httpRequest.dispose( [request] )
end-if
end-try
end-function
You can invoke a qualifier just like the function of a business object. This will look for the main function in the implementation file. It assumes that the first parameter is a qualified property bag.
The above example can thus be invoked as follows:
qualifier.invoke( <@curl> )
or:
qualifier.invoke(
<@curl
url: 'https://meowfacts.herokuapp.com/'
type: 'json'
>
)
(the first example works because both qualifier tags have default values).
<End of document>