public abstract class Action<A extends Action> extends Rule<A>
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.
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.
Rule.RuleMatcherconfigMap, configStr, excludeMatchers, includeMatchers, log, name, order| Constructor and Description |
|---|
Action() |
Action(java.lang.String methods,
java.lang.String... includePaths) |
| Modifier and Type | Method and Description |
|---|---|
void |
doDelete(Request req,
Response res)
Handle an HTTP DELETE.
|
void |
doGet(Request req,
Response res)
Handle an HTTP GET.
|
void |
doPatch(Request req,
Response res)
Handle an HTTP PATCH.
|
void |
doPost(Request req,
Response res)
Handle an HTTP POST.
|
void |
doPut(Request req,
Response res)
Handle an HTTP PUT.
|
void |
run(Request req,
Response res)
Override this method with your custom business logic or override one of the
http method "doMETHOD" specific handlers.
|
checkLazyConfig, compareTo, doLazyConfig, getConfig, getConfig, getConfigKeys, getDefaultIncludeMatch, getExcludeMatchers, getExcludePaths, getIncludeMatchers, getIncludePaths, getName, getOrder, match, matches, matches, toString, withConfig, withExcludeOn, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withIncludeOn, withName, withOrderpublic Action()
public Action(java.lang.String methods,
java.lang.String... includePaths)
public void run(Request req, Response res) throws ApiException
req - the Request being servicedres - the Reponse being generatedApiExceptionpublic void doGet(Request req, Response res) throws ApiException
Override run() or override this method with your business logic, otherwise a 501 will be thrown if it is called.
req - res - ApiExceptionpublic void doPost(Request req, Response res) throws ApiException
Override run() or override this method with your business logic, otherwise a 501 will be thrown if it is called.
req - res - ApiExceptionpublic void doPut(Request req, Response res) throws ApiException
Override run() or override this method with your business logic, otherwise a 501 will be thrown if it is called.
req - res - ApiExceptionpublic void doPatch(Request req, Response res) throws ApiException
Override run() or override this method with your business logic, otherwise a 501 will be thrown if it is called.
req - res - ApiExceptionpublic void doDelete(Request req, Response res) throws ApiException
Override run() or override this method with your business logic, otherwise a 501 will be thrown if it is called.
req - res - ApiExceptionCopyright © 2024 Rocket Partners, LLC. All rights reserved.