1
0
Fork 0
arangodb/Doxygen/doc/JSModuleActions.html

120 lines
8.8 KiB
HTML

<html><head><title>ArangoDB Manual</title> <style media="screen" type="text/css" style="display:none">body{background-color:white;font:13px Helvetica,arial,freesans,clean,sans-serif;line-height:1.4;color:#333;}#access{font-size:16px;margin-left:12px;display:block;margin-left:10px;margin-right:10px;background-color:#F3F1EE!important;}#access a{border-right:1px solid #DBDEDF;color:#A49F96;display:block;line-height:38px;padding:0 10px;text-decoration:none;}#navigation ul{text-transform:uppercase;list-style:none;margin:0;}#navigation li{float:left;position:relative;}#container{width:920px;margin:0 auto;}a{color:#4183C4;text-decoration:none;}.contents h2{font-size:24px;border-bottom:1px solid #CCC;color:black;}.contents h1{font-size:33px;border-bottom:1px solid #CCC;color:black;}.clearfix:after{content:".";display:block;clear:both;font-size:0;height:0;visibility:hidden;}/**/ *:first-child+html .clearfix{min-height:0;}/**/ * html .clearfix{height:1%;}</style></head><body><div id="container"><img src="images/logo_arangodb.png" width="397" height="67" alt="ArangoDB"><div id="access" role="navigation"><div id="navigation"><ul id="menu-ahome" class="menu"><li><a href="Home.html">Table of contents</a></li> <li><a href="http://www.arangodb.org">ArangoDB homepage</a></li></ul></div><div class="clearfix"></div></div><div>
<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div class="header">
<div class="headertitle">
<h1>Module "actions" </h1> </div>
</div>
<div class="contents">
<div class="textblock"><p>The action module provides the infrastructure for defining HTTP actions.</p>
<hr/>
<ol>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsBasics">Basics</a> <ol>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsDefineHttp">actions.defineHttp</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultError">actions.resultError</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsGetErrorMessage">actions.getErrorMessage</a> </li>
</ol>
</li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsHTTP">Standard HTTP Result Generators</a> <ol>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultOk">actions.resultOK</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultBad">actions.resultBad</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultNotFound">actions.resultNotFound</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultUnsupported">actions.resultUnsupported</a> </li>
</ol>
</li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsArangoDB">ArangoDB Result Generators</a> <ol>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsCollectionNotFound">actions.collectionNotFound</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsIndexNotFound">actions.indexNotFound</a> </li>
<li>
<a class="el" href="JSModuleActions.html#JSModuleActionsResultException">actions.resultException</a> </li>
</ol>
</li>
</ol>
<hr/>
<h2><a class="anchor" id="JSModuleActionsBasics"></a>
Basics</h2>
<p><a class="anchor" id="JSModuleActionsDefineHttp"></a> <hr/>
<code><b>actions.defineHttp(<em>options</em>)</b></code><hr/>
Defines a new action. The <em>options</em> are as follows:</p>
<p><em>options.url</em></p>
<p>The URL, which can be used to access the action. This path might contain slashes. Note that this action will also be called, if a url is given such that <em>options.url</em> is a prefix of the given url and no longer definition matches.</p>
<p><em>options.prefix</em></p>
<p>If <code>false</code>, then only use the action for excat matches. The default is <code>true</code>.</p>
<p><em>options.context</em></p>
<p>The context to which this actions belongs. Possible values are "admin", "monitoring", "api", and "user". All contexts apart from "user" are reserved for system actions and are database independent. All actions except "user" and "api" are executed in a different worker queue than the normal queue for clients. The "api" actions are used by the client api to communicate with the ArangoDB server. Both the "api" and "user" actions are using the same worker queue.</p>
<p>It is possible to specify a list of contexts, in case an actions belongs to more than one context.</p>
<p>Note that the url for "user" actions is automatically prefixed with <code>_action</code>. This applies to all specified contexts. For example, if the context contains "admin" and "user" and the url is <code>hallo</code>, then the action is accessible under <code>/_action/hallo</code> - even for the admin context.</p>
<p><em>options.callback</em>(<em>request</em>, <em>response</em>)</p>
<p>The request argument contains a description of the request. A request parameter <code>foo</code> is accessible as <code>request.parametrs.foo</code>. A request header <code>bar</code> is accessible as <code>request.headers.bar</code>. Assume that the action is defined for the url <code>/foo/bar</code> and the request url is <code>/foo/bar/hugo/egon</code>. Then the suffix parts <code>[ "hugon", "egon" ]</code> are availible in <code>request.suffix</code>.</p>
<p>The callback must define fill the <em>response</em>.</p>
<ul>
<li><code><em>response</em>.responseCode</code>: the response code</li>
<li><code><em>response</em>.contentType</code>: the content type of the response</li>
<li><code><em>response</em>.body</code>: the body of the response</li>
</ul>
<p>You can use the functions <code>ResultOk</code> and <code>ResultError</code> to easily generate a response.</p>
<p><em>options.parameters</em></p>
<p>Normally the parameters are passed to the callback as strings. You can use the <em>options</em>, to force a converstion of the parameter to</p>
<ul>
<li><code>"collection"</code> </li>
<li><code>"collection-identifier"</code> </li>
<li><code>"collection-name"</code> </li>
<li><code>"number"</code> </li>
<li><code>"string"</code> </li>
</ul>
<hr/>
<p><a class="anchor" id="JSModuleActionsResultError"></a> <hr/>
<code><b>actions.resultError(<em>req</em>, <em>res</em>, <em>code</em>, <em>errorNum</em>, <em>errorMessage</em>, <em>headers</em>, <em>keyvals</em>)</b></code><hr/>
The functions generates an error response. The response body is an array with an attribute <code>errorMessage</code> containing the error message <em>errorMessage</em>, <code>error</code> containing <code>true</code>, <code>code</code> containing <em>code</em>, <code>errorNum</code> containing <em>errorNum</em>, and <code>errorMessage</code> containing the error message <em>errorMessage</em>. <em>keyvals</em> are mixed into the result. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsGetErrorMessage"></a> <hr/>
<code><b>actions.getErrorMessage(<em>code</em>)</b></code><hr/>
Returns the error message for an error code. </p>
<hr/>
<h2><a class="anchor" id="JSModuleActionsHTTP"></a>
Standard HTTP Result Generators</h2>
<p><a class="anchor" id="JSModuleActionsResultOk"></a> <hr/>
<code><b>actions.resultOk(<em>req</em>, <em>res</em>, <em>code</em>, <em>result</em>, <em>headers</em></b></code><hr/>
)}</p>
<p>The functions defines a response. <em>code</em> is the status code to return. <em>result</em> is the result object, which will be returned as JSON object in the body. <code>headers</code> is an array of headers to returned. The function adds the attribute <code>error</code> with value <code>false</code> and <code>code</code> with value <em>code</em> to the <em>result</em>. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsResultBad"></a> <hr/>
<code><b>actions.resultBad(<em>req</em>, <em>res</em>, <em>error-code</em>, <em>msg</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsResultNotFound"></a> <hr/>
<code><b>actions.resultNotFound(<em>req</em>, <em>res</em>, <em>msg</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsResultUnsupported"></a> <hr/>
<code><b>actions.resultUnsupported(<em>req</em>, <em>res</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
<hr/>
<h2><a class="anchor" id="JSModuleActionsArangoDB"></a>
ArangoDB Result Generators</h2>
<p><a class="anchor" id="JSModuleActionsCollectionNotFound"></a> <hr/>
<code><b>actions.collectionNotFound(<em>req</em>, <em>res</em>, <em>collection</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsIndexNotFound"></a> <hr/>
<code><b>actions.collectionNotFound(<em>req</em>, <em>res</em>, <em>collection</em>, <em>index</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
<hr/>
<p><a class="anchor" id="JSModuleActionsResultException"></a> <hr/>
<code><b>actions.resultException(<em>req</em>, <em>res</em>, <em>err</em>, <em>headers</em>)</b></code><hr/>
The functions generates an error response. </p>
</div></div>
</div></body></html>