Package io.inversion

Class Api


  • public final class Api
    extends java.lang.Object
    Contains the Servers, Dbs, Collections, Endpoints and Actions that make up a REST API.
    • 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
    • Constructor Detail

      • Api

        public Api()
      • Api

        public Api​(java.lang.String name)
    • 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:
        toString in class java.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)
      • withServer

        public Api withServer​(Server server)
      • 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
      • withDbs

        public Api withDbs​(Db... dbs)
        Parameters:
        dbs - the dbs to set
        Returns:
        this
      • withDbs

        public Api withDbs​(java.util.List<Db> dbs)
      • withDb

        public <T extends DbApi withDb​(Db<T> db)
      • 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()
      • removeEndpoint

        public Api removeEndpoint​(Endpoint ep)
      • withEndpoint

        public Api withEndpoint​(Action action1,
                                Action... actions)
      • withEndpoint

        public Api withEndpoint​(java.lang.String ruleMatcherSpec,
                                Action... actions)
      • withEndpoint

        public Api withEndpoint​(Endpoint... endpoints)
      • 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 collection
        parentPropertyName - the name of the json property for the parent that references the children (optional)
        childCollectionName - the target child collection name
        childPropertyName - 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
      • withAction

        public Api withAction​(Action action)
      • 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()
      • withLinker

        public Api withLinker​(Linker linker)
      • 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)