Package io.inversion

Class Api

All Implemented Interfaces:
Comparable<Api>

public class Api extends Rule<Api>
Contains the Collections, Endpoints and Actions that make up a REST API.
  • Field Details

    • dbs

      protected final List<Db> dbs
      The underlying data sources for the Api.
    • endpoints

      protected final 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 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 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 List<Api.ApiListener> listeners
      Listeners that receive callbacks on startup/shutdown/request/error.
    • hash

      protected transient String hash
    • debug

      protected boolean debug
    • url

      protected String url
  • Constructor Details

    • Api

      public Api()
    • Api

      public Api(String name)
  • Method Details

    • getDefaultIncludeMatch

      protected Rule.RuleMatcher getDefaultIncludeMatch()
      Description copied from class: Rule
      Designed to allow subclasses to provide a default match behavior of no configuration was provided by the developer.
      Overrides:
      getDefaultIncludeMatch in class Rule<Api>
      Returns:
      the default include match "*","*"
    • isStarted

      public boolean isStarted()
    • removeExcludes

      public void removeExcludes()
    • getHash

      public String getHash()
    • withHash

      public Api withHash(String hash)
    • withCollection

      public Api withCollection(Collection coll)
    • getCollections

      public List<Collection> getCollections()
    • getCollection

      public Collection getCollection(String name)
    • getDb

      public Db getDb(String name)
    • getDbs

      public List<Db> getDbs()
      Returns:
      the dbs
    • withDbs

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

      public <T extends Db> Api withDb(Db<T> db)
    • getLoadTime

      public long getLoadTime()
    • setLoadTime

      public void setLoadTime(long loadTime)
    • getEndpoints

      public List<Endpoint> getEndpoints()
    • withEndpoint

      public Api withEndpoint(String methods, String includePaths, Action... actions)
    • withEndpoint

      public Api withEndpoint(Endpoint... endpoints)
    • 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 collection
      parentPropertyName - the name of the json property for the parent that references the child
      childCollectionName - the target child collection name
      childPropertyName - the name of hte json property for the child that references the parent
      childFkProps - 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 childFkProps will generally match the length of parentCollections primary index. If the two don't match, then childFkProps must 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 to
      parentPropertyName - the name of the json property for the parent that references the child
      childCollection - the target child collection
      childPropertyName - the name of hte json property for the child that references the parent
      childFkProps - Properties that make up the foreign key
      Returns:
      this
    • getActions

      public 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)
    • isDebug

      public boolean isDebug()
    • setDebug

      public void setDebug(boolean debug)
    • getUrl

      public String getUrl()
    • withUrl

      public Api withUrl(String url)
    • withApiListener

      public Api withApiListener(Api.ApiListener listener)
    • getApiListeners

      public List<Api.ApiListener> getApiListeners()