Class Api
- java.lang.Object
-
- io.inversion.Api
-
public final class Api extends java.lang.ObjectContains the Servers, Dbs, Collections, Endpoints and Actions that make up a REST API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceApi.ApiListenerListener that can be registered with anApito receive lifecycle, per request and per error callback notifications.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Action>actionsActions that may be selected to run regardless of the matched Endpoint.protected java.util.List<Collection>collectionsThe data objects being served by this API.protected java.util.List<Db>dbsThe underlying data sources for the Api.protected booleandebugprotected java.util.List<Endpoint>endpointsThe Request HTTP method/path combinations that map to a distinct set of Actions.protected java.lang.Stringhashprotected Linkerlinkerprotected java.util.List<Api.ApiListener>listenersListeners that receive callbacks on startup/shutdown/request/error.protected org.slf4j.Loggerlogprotected java.lang.Stringnameprotected java.util.List<Op>opsprotected java.util.List<Server>serversHost and root path configprotected java.lang.Stringurlprotected java.lang.Stringversion
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActiongetAction(java.lang.String name)java.util.List<Action>getActions()java.util.List<Api.ApiListener>getApiListeners()CollectiongetCollection(java.lang.String name)java.util.List<Collection>getCollections()DbgetDb(java.lang.String name)java.util.List<Db>getDbs()EndpointgetEndpoint(java.lang.String name)java.util.List<Endpoint>getEndpoints()EnginegetEngine()java.lang.StringgetHash()LinkergetLinker()longgetLoadTime()java.lang.StringgetName()OpgetOp(java.lang.String name)java.util.List<Op>getOps()java.util.List<Server>getServers()java.lang.StringgetUrl()java.lang.StringgetVersion()booleanisDebug()booleanisStarted()DbmatchDb(java.lang.String method, io.inversion.utils.Path requestPath)ApiremoveEndpoint(Endpoint ep)voidremoveExcludes()voidsetDebug(boolean debug)voidsetLoadTime(long loadTime)java.lang.StringtoString()ApiwithAction(Action action)ApiwithActions(Action... actions)Add Action(s) may be selected to run across multiple Endpoints.ApiwithApiListener(Api.ApiListener listener)ApiwithCollection(Collection coll)<T extends Db>
ApiwithDb(Db<T> db)ApiwithDbs(Db... dbs)ApiwithDbs(java.util.List<Db> dbs)ApiwithDebug(boolean debug)voidwithDelayedConfig(java.lang.Runnable r)ApiwithEndpoint(Action action1, Action... actions)ApiwithEndpoint(Endpoint... endpoints)ApiwithEndpoint(java.lang.String ruleMatcherSpec, Action... actions)ApiwithHash(java.lang.String hash)ApiwithLinker(Linker linker)ApiwithName(java.lang.String name)ApiwithRelationship(java.lang.String parentCollectionName, java.lang.String parentPropertyName, java.lang.String childCollectionName, java.lang.String childPropertyName, java.lang.String... 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.ApiwithServer(Server server)ApiwithServers(java.lang.String... urls)ApiwithUrl(java.lang.String url)ApiwithVersion(java.lang.String version)
-
-
-
Field Detail
-
log
protected final transient org.slf4j.Logger log
-
servers
protected final java.util.List<Server> servers
Host and root path config
-
dbs
protected final java.util.List<Db> dbs
The underlying data sources for the Api.
-
endpoints
protected final java.util.List<Endpoint> 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
protected final java.util.List<Action> 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
protected final java.util.List<Collection> 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
protected final transient java.util.List<Api.ApiListener> listeners
Listeners that receive callbacks on startup/shutdown/request/error.
-
linker
protected transient Linker linker
-
ops
protected transient java.util.List<Op> ops
-
name
protected java.lang.String name
-
hash
protected transient java.lang.String hash
-
debug
protected boolean debug
-
url
protected java.lang.String url
-
version
protected java.lang.String version
-
-
Method Detail
-
isStarted
public boolean isStarted()
-
withDelayedConfig
public void withDelayedConfig(java.lang.Runnable r)
-
removeExcludes
public void removeExcludes()
-
getHash
public java.lang.String getHash()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withHash
public Api withHash(java.lang.String hash)
-
getServers
public java.util.List<Server> getServers()
-
withServers
public Api withServers(java.lang.String... urls)
-
withCollection
public Api withCollection(Collection coll)
-
getCollections
public java.util.List<Collection> getCollections()
-
getCollection
public Collection getCollection(java.lang.String name)
-
getDb
public Db getDb(java.lang.String name)
-
getDbs
public java.util.List<Db> getDbs()
- Returns:
- the dbs
-
getName
public java.lang.String getName()
-
withName
public Api withName(java.lang.String name)
-
withVersion
public Api withVersion(java.lang.String version)
-
getVersion
public java.lang.String getVersion()
-
getLoadTime
public long getLoadTime()
-
setLoadTime
public void setLoadTime(long loadTime)
-
getEndpoint
public Endpoint getEndpoint(java.lang.String name)
-
getEndpoints
public java.util.List<Endpoint> getEndpoints()
-
withRelationship
public Api withRelationship(java.lang.String parentCollectionName, java.lang.String parentPropertyName, java.lang.String childCollectionName, java.lang.String childPropertyName, java.lang.String... 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.If parentPropertyName is null, the ONE_TO_MANY relationship will not be crated.
If childPropertyName is null, the MANY_TO_ONE relationship will not be created.
If both parentPropertyName and childPropertyName are null, nothing will be performed, this will be a noop.
This configuration does not occur until after the Api has been started so that underlying Collections/Properties don't have to exist.
- Parameters:
parentCollectionName- the name of the parent collectionparentPropertyName- the name of the json property for the parent that references the children (optional)childCollectionName- the target child collection namechildPropertyName- the name of hte json property for the child that references the parent (optional)childFkProps- names of the existing Properties that make up the foreign key- Returns:
- this
- See Also:
Collection.withOneToManyRelationship(String, Collection, String...),Collection.withManyToOneRelationship(String, Collection, String...)
-
getAction
public Action getAction(java.lang.String name)
-
getActions
public java.util.List<Action> getActions()
-
withActions
public Api withActions(Action... actions)
Add Action(s) may be selected to run across multiple Endpoints.- Parameters:
actions- actions to match and conditionally run across all Requests- Returns:
- this
-
getEngine
public Engine getEngine()
-
isDebug
public boolean isDebug()
-
withDebug
public Api withDebug(boolean debug)
-
setDebug
public void setDebug(boolean debug)
-
getUrl
public java.lang.String getUrl()
-
withUrl
public Api withUrl(java.lang.String url)
-
getLinker
public Linker getLinker()
-
withApiListener
public Api withApiListener(Api.ApiListener listener)
-
getApiListeners
public java.util.List<Api.ApiListener> getApiListeners()
-
matchDb
public Db matchDb(java.lang.String method, io.inversion.utils.Path requestPath)
-
getOps
public java.util.List<Op> getOps()
-
getOp
public Op getOp(java.lang.String name)
-
-