<div class="container-fluid">
<div class="row-fluid">
    <div class="page-header">
        <h1>API</h1>
    </div>
</div>
<div class="row-fluid">
  <p>
    If you are using forms-angular in the most common way, your users will be using the <a href="/#/forms#routes">client side routes</a> (dountless through links that you have set up for them) and you
    won't need to know any of the back end APIs.  But, in an attempt at completeness they are listed below.  It is sometimes useful to fall down to this level to set up AJAX queries to populate
    the options on a <a href="//github.com/forms-angular/fng-ui-select">select</a> for instance.
  </p>
  <p>
    All the examples below assume that the urlPrefix was left at the default (/api/) when instantiating the server side of forms-angular.
  </p>
  <h2>GET</h2>
    <ul>
        <li>Models
            <ul>
                <li><strong>/api/models</strong> returns an array of all the models that are available to forms-angular</li>
                <li><strong>/api/schema/:model</strong> returns the schema for a model</li>
                <li><strong>/api/schema/:model/:customForm</strong> returns the schema for a model</li>
                <li><strong>/api/:model</strong> returns an array of all the documents in a model.  A simple example is
                  to return all the items in a model, as in <a href="/api/b_enhanced_schema"><code>/api/b_enhanced_schema</code></a>,
                  but this can be adapted using several options (which may be used together, linked by an <strong>&</strong> character):</li>
                  <ul>
                    <li><strong>f</strong>ilter using a JSON object.  For example <a href="/api/b_enhanced_schema?f={%22forename%22:%22Alan%22}"><code>/api/b_enhanced_schema?f={"forename":"Alan"}</code></a></li>
                    <li><strong>l</strong>imit.  For example <a href="/api/b_enhanced_schema?l=10"><code>/api/b_enhanced_schema?l=10</code></a>.  (Used with <strong>s</strong>kip option to provide pagination)</li>
                    <li><strong>s</strong>kip.  For example <a href="/api/b_enhanced_schema?s=10"><code>/api/b_enhanced_schema?s=10</code></a>.  (Used with <strong>l</strong>imit option to provide pagination)</li>
                    <li><strong>o</strong>rder using a JSON object.  For example <a href="/api/b_enhanced_schema?o={%22forename%22:1,%22dateOfBirth%22:-1}"><code>/api/b_enhanced_schema?o={"forename":1,"dateOfBirth":-1}</code></a> sorts by forename by youth</li>
                    <li><strong>p</strong>roject (return secified fields) using a JSON object.  For example <a href="/api/b_enhanced_schema?p={%22surname%22:1}"><code>/api/b_enhanced_schema?p={"surname":1}</code></a> returns only surname.  _id is always returned. 0 suppresses a field.  You cannot mix suppression and selection.</li>
                    <li><strong>a</strong>ggregation using a JSON object, gives access to the very powerful (and quite difficult) MongoDB <a href="https://docs.mongodb.org/manual/core/aggregation-introduction/">aggregation framework</a>.
                    The normal use case here is to use the aggregation framework to perform a <strong>$match</strong>.  Any $project steps must return the original _id.
                  </ul>
                <li><strong>/api/:model/:id</strong> a single document from the collection.  You can <strong>project</strong> fields here (see above for details)</li>
                <li><strong>/api/:model/:id/list</strong> returns how a document should appear in a list</li>
            </ul>

            <p>The calls that return data will strip out any fields that are defined as <strong>secure</strong> - for example
            <pre><code>passwordHash: {type: String, secure:true, form: {hidden: true}}</code></pre></p>
        </li>
        <li>Search
            <ul>
                <li><strong>/api/search?q=string</strong> returns documents where the string is found at the beginning of an
                    indexed field
                </li>
                <li><strong>/api/search/:model?q=string</strong> returns documents in the specified collection where the string
                    is found at the beginning of an indexed field. Note that the search is case insensitive, so will be
                    inefficient (and to be avoided on large datasets) until Mongo DB offers case insensitive indexing. (See issue <a
                            href="https://jira.mongodb.org/browse/SERVER-90" target="_blank">here</a>)
                </li>
                <li><strong>/api/search?q=string&f={<span><em>filterjson</em></span>}</strong> returns documents where the
                    string is found at the beginning of an indexed field which satisfy the conditions in the filter.
                </li>
            </ul>
        </li>
    </ul>
  <h2>POST</h2>
  <ul>
    <li><strong>/api/:model</strong> creates a new document in a collection</li>
    <li><strong>/api/:model/:id</strong> updates document with specified _id in a collection</li>
  </ul>
  <h2>DELETE</h2>
  <ul>
    <li><strong>/api/:model/:id</strong> removes document with specified _id from a collection</li>
  </ul>

</div>
</div>
