When developing CAP services, I often stumble upon testing actions and functions, because URI patterns vary depending on action / function, if it is bound or unbound, and OData version. That's why I decided to write this short blog post for my reference. I hope this also helps someone else.
To test the examples below, clone the following GitHub repository and run
cds watch
.
https://github.com/miyasuta/actions-and-functions
*Actions cannot be tested form the browser. Use tools such as
Postman or
REST Client (VS Code extension) and send a POST request.
To learn more about CAP actions and functions, and what are bound / unbound actions / functions, please find the document below.
https://cap.cloud.sap/docs/cds/cdl#actions
OData V4
Actions
General patterns
- Bound Action:
pathToService/EntitySet(key)/ServiceName.actionName
- Unbound Action:
pathToService/actionName
Examples
Note that you need the header
content-type: application/json
, even if the action doesn't require parameters.
Functions
General patterns
Parenthesis() are required after function names.
- Bound function:
pathToService/EntitySet(key)/ServiceName.functionName(paramName1=<value>,paramName2=<value>
)
- Unbound function:
pathToService/functionName(paramName1=<value>,paramName2=<value>)
Examples
OData V2
Actions
General patterns
Two URI patterns are accepted for bound actions. Pattern1 is the same as v4, and pattern2 is specific to v2.
- Bound Action (pattern1):
pathToService/EntitySet(key)/ServiceName.actionName
- Bound Action (pattern2):
pathToService/EntitySet_actionName?key=<value>
- Unbound Action:
pathToService/actionName
Examples
Note that you need the header
content-type: application/json
, even if the action doesn't require parameters.
Functions
General patterns
OData V2 functions work with or without parenthesis() after function names.
- Bound function:
pathToService/EntitySet_functionName?key=<value>¶mName1=<value>¶mName2=<value>
- Unbound function:
pathToService/functionName?paramName1=<value>¶mName2=<value>
Examples