Package io.inversion
Class Api
- All Implemented Interfaces:
Comparable<Api>
Contains the Collections, Endpoints and Actions that make up a REST API.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener that can be registered with anApito receive lifecycle, per request and per error callback notifications.Nested classes/interfaces inherited from class io.inversion.Rule
Rule.RuleMatcher -
Field Summary
FieldsModifier and TypeFieldDescriptionActions that may be selected to run regardless of the matched Endpoint.protected final List<Collection>The data objects being served by this API.The underlying data sources for the Api.protected booleanThe Request HTTP method/path combinations that map to a distinct set of Actions.protected Stringprotected final List<Api.ApiListener>Listeners that receive callbacks on startup/shutdown/request/error.protected StringFields inherited from class io.inversion.Rule
configMap, configStr, excludeMatchers, excludeOn, includeMatchers, includeOn, log, name, order -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCollection(String name) getDbs()protected Rule.RuleMatcherDesigned to allow subclasses to provide a default match behavior of no configuration was provided by the developer.getHash()longgetUrl()booleanisDebug()booleanvoidvoidsetDebug(boolean debug) voidsetLoadTime(long loadTime) withAction(Action action) withActions(Action... actions) Add Action(s) may be selected to run across multiple Endpoints.withApiListener(Api.ApiListener listener) withCollection(Collection coll) withEndpoint(Endpoint... endpoints) withEndpoint(String methods, String includePaths, Action... actions) withRelationship(Collection parentCollection, String parentPropertyName, Collection childCollection, String childPropertyName, Property... childFkProps) Creates a ONE_TO_MANY Relationship from the parent to child collection and the inverse MANY_TO_ONE from the child to the parent.withRelationship(String parentCollectionName, String parentPropertyName, String childCollectionName, String childPropertyName, String... childFkProps) This method takes String instead of actual Collections and Properties as a convenience to people hand wiring up an Api.Methods inherited from class io.inversion.Rule
checkLazyConfig, compareTo, doLazyConfig, getAllExcludePaths, getAllIncludePaths, getConfig, getConfig, getConfigKeys, getExcludeMatchers, getIncludeMatchers, getName, getOrder, match, matches, matches, toString, withConfig, withExcludeOn, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withIncludeOn, withName, withOrder
-
Field Details
-
dbs
The underlying data sources for the Api. -
endpoints
The Request HTTP method/path combinations that map to a distinct set of Actions.A single Endpoint will be selected to run to service a Request. Any additional Path matching rules that exist on these Endpoint's Actions will be interpreted as relative to the end of the selected Endpoint's Path match.
-
actions
Actions that may be selected to run regardless of the matched Endpoint.The Action's Path match statements will be considered relative to the Api's base URL NOT relative to the selected Endpoint.
-
collections
The data objects being served by this API. In a simple API these may map one-to-one to, for example, database tables from a JdbcDb connecting to a RDBMS such as MySql or SqlServer. -
listeners
Listeners that receive callbacks on startup/shutdown/request/error. -
hash
-
debug
protected boolean debug -
url
-
-
Constructor Details
-
Api
public Api() -
Api
-
-
Method Details
-
getDefaultIncludeMatch
Description copied from class:RuleDesigned to allow subclasses to provide a default match behavior of no configuration was provided by the developer.- Overrides:
getDefaultIncludeMatchin classRule<Api>- Returns:
- the default include match "*","*"
-
isStarted
public boolean isStarted() -
removeExcludes
public void removeExcludes() -
getHash
-
withHash
-
withCollection
-
getCollections
-
getCollection
-
getDb
-
getDbs
- Returns:
- the dbs
-
withDbs
- Parameters:
dbs- the dbs to set- Returns:
- this
-
withDb
-
getLoadTime
public long getLoadTime() -
setLoadTime
public void setLoadTime(long loadTime) -
getEndpoints
-
withEndpoint
-
withEndpoint
-
withRelationship
public Api withRelationship(String parentCollectionName, String parentPropertyName, String childCollectionName, String childPropertyName, String... childFkProps) This method takes String instead of actual Collections and Properties as a convenience to people hand wiring up an Api. The referenced Collections and Properties actually have to exist already or you will get a NPE.- Parameters:
parentCollectionName- the name of the parent collectionparentPropertyName- the name of the json property for the parent that references the childchildCollectionName- the target child collection namechildPropertyName- the name of hte json property for the child that references the parentchildFkProps- names of the existing Properties that make up the foreign key- Returns:
- this
-
withRelationship
public Api withRelationship(Collection parentCollection, String parentPropertyName, Collection childCollection, String childPropertyName, Property... childFkProps) Creates a ONE_TO_MANY Relationship from the parent to child collection and the inverse MANY_TO_ONE from the child to the parent. The Relationship object along with the required Index objects are created.For collections backed by relational data sources (like a SQL db) the length of
childFkPropswill generally match the length ofparentCollectionsprimary index. If the two don't match, thenchildFkPropsmust be 1. In this case, the compound primary index of parentCollection will be encoded as an resourceKey in the single child table property.- Parameters:
parentCollection- the collection to add the relationship toparentPropertyName- the name of the json property for the parent that references the childchildCollection- the target child collectionchildPropertyName- the name of hte json property for the child that references the parentchildFkProps- Properties that make up the foreign key- Returns:
- this
-
getActions
-
withActions
Add Action(s) may be selected to run across multiple Endpoints.- Parameters:
actions- actions to match and conditionally run across all Requests- Returns:
- this
-
withAction
-
isDebug
public boolean isDebug() -
setDebug
public void setDebug(boolean debug) -
getUrl
-
withUrl
-
withApiListener
-
getApiListeners
-