Class Action<A extends Action>
- All Implemented Interfaces:
Comparable<A>
- Direct Known Subclasses:
AclAction,AuthAction,CsvAction,DbAction,DbDeleteAction,DbGetAction,DbPostAction,MockAction
The Action Sandwich
Nearly the entire job of the Engine and Api Endpoint configuration is to match one or more Action subclass instances to a Request.
All matched actions are sorted by their order property and executed in sequence as a Chain of Responsibility pattern.
Colloquially, at Rocket Partners we somehow started to call this the 'action sandwich'.
If an Action should be run across multiple Endpoints, a logging or security Action for example, it can be added directly to an Api via Api.withAction.
In most cases however, you will group sets of related actions under an Endpoint and add the Endpoint to the Api.
Both Api registered Actions and Endpoint registered Actions can be selected into the 'action sandwich' for a particular Request.
One big difference however is that includesPaths and excludePaths are relative to the Api path for
Api registered Actions and relative to the Endpoint path for Endpoint registered actions. They are all sorted togeter in one big group according to order.
Handling Requests
Once the Engine has selected the Actions to run for a given request (creating the 'action sandwich'), they are all loaded into a Chain object
which is responsible for invoking run(Request, Response) on each one in sequence.
You can override run to process all Requests this Action is selected for, or you can override any of the HTTP method specific doGet/Post/Put/Patch/Delete() handlers
if you want to segregate your business logic by HTTP method.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.inversion.Rule
Rule.RuleMatcher -
Field Summary
Fields inherited from class io.inversion.Rule
configMap, configStr, excludeMatchers, excludeOn, includeMatchers, includeOn, log, name, order -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidHandle an HTTP DELETE.voidHandle an HTTP GET.voidHandle an HTTP PATCH.voidHandle an HTTP POST.voidHandle an HTTP PUT.voidOverride this method with your custom business logic or override one of the http method "doMETHOD" specific handlers.protected voidMethods inherited from class io.inversion.Rule
checkLazyConfig, compareTo, doLazyConfig, getAllExcludePaths, getAllIncludePaths, getConfig, getConfig, getConfigKeys, getDefaultIncludeMatch, getExcludeMatchers, getIncludeMatchers, getName, getOrder, match, matches, matches, toString, withConfig, withExcludeOn, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withIncludeOn, withName, withOrder
-
Constructor Details
-
Action
public Action() -
Action
- Parameters:
methods- a comma separated list of http methods to matchpaths- a comma separated list of url paths to match
-
-
Method Details
-
run
Override this method with your custom business logic or override one of the http method "doMETHOD" specific handlers.- Parameters:
req- the Request being servicedres- the Reponse being generated- Throws:
ApiException
-
run0
- Throws:
ApiException
-
doGet
Handle an HTTP GET.Override run() to handle all requests or override this method with your business logic specifically for a GET request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPost
Handle an HTTP POST.Override run() to handle all requests or override this method with your business logic for a POST request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPut
Handle an HTTP PUT.Override run() to handle all requests or override this method with your business logic for a PUT request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPatch
Handle an HTTP PATCH.Override run() to handle all requests or override this method with your business logic for a PATCH request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doDelete
Handle an HTTP DELETE.Override run() to handle all requests or override this method with your business logic for a DELETE request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-