1
0
Fork 0

Examplify

This commit is contained in:
Willi Goesgens 2015-08-07 11:45:39 +02:00 committed by Michael Hackstein
parent 20cc96096f
commit dd19fdf077
4 changed files with 127 additions and 144 deletions

View File

@ -2,16 +2,18 @@
If you change the example slightly, then a JSON object will be delivered.
```js
arangosh> db._routing.save({
url: "/hello/json",
content: {
contentType: "application/json",
body: "{ \"hello\" : \"world\" }"
}
});
arangosh> require("internal").reloadRouting()
```
@startDocuBlockInline routingCreateHelloWorld
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateHelloWorld}
|db._routing.save({
| url: "/hello/json",
| content: {
| contentType: "application/json",
| body: "{ \"hello\" : \"world\" }"
| }
});
require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateHelloWorld
Again check with your browser http:// localhost:8529/hello/json
@ -21,10 +23,15 @@ application to display the JSON object, you can change the *contentType* to
*"text/plain"* for the example. This makes it easier to check the example using
a browser. Or use *curl* to access the server.
```js
bash> curl "http://127.0.0.1:8529/hello/json" && echo
{ "hello" : "world" }
```
@startDocuBlockInline routingCurlHelloWorld
@EXAMPLE_ARANGOSH_RUN{routingCurlHelloWorld}
var url = "/hello/json";
var response = logCurlRequest('GET', url);
assert(response.code === 200);
logJsonResponse(response);
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCurlHelloWorld
!SECTION Delivering Content
@ -83,37 +90,27 @@ function (req, res, options, next)
*Examples*
```js
arangosh> db._routing.save({
url: "/hello/echo",
action: {
do: "org/arangodb/actions/echoRequest"
}
});
```
@startDocuBlockInline routingCreateHelloEcho
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateHelloEcho}
|db._routing.save({
| url: "/hello/echo",
| action: {
| do: "org/arangodb/actions/echoRequest"
| }
});
~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateHelloEcho
Reload the routing and check http:// 127.0.0.1:8529/hello/echo
You should see something like
```js
{
"request": {
"path": "/hello/echo",
"headers": {
"accept-encoding": "gzip, deflate",
"accept-language": "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
"connection": "keep-alive",
"content-length": "0",
"host": "localhost:8529",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0"
},
"requestType": "GET",
"parameters": { }
},
"options": { }
}
```
@startDocuBlockInline fetchroutingCreateHelloEcho
@EXAMPLE_ARANGOSH_OUTPUT{fetchroutingCreateHelloEcho}
arango.GET("hello/echo")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock fetchroutingCreateHelloEcho
The request might contain *path*, *prefix*, *suffix*, and *urlParameters*
attributes. *path* is the complete path as supplied by the user and always
@ -151,14 +148,17 @@ called.
*Examples*
```js
arangosh> db._routing.save({
url: "/hello/echo",
action: {
controller: "org/arangodb/actions/echoController"
}
});
```
@startDocuBlockInline routingCreateEchoController
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoController}
|db._routing.save({
| url: "/hello/echo",
| action: {
| controller: "org/arangodb/actions/echoController"
| }
});
~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoController
!SUBSECTION Prefix Action Controller
@ -206,14 +206,18 @@ You can also store a function directly in the routing table.
*Examples*
```js
arangosh> db._routing.save({
url: "/hello/echo",
action: {
callback: "function(req,res) {res.statusCode=200; res.body='Hello'}"
}
});
```
@startDocuBlockInline routingCreateEchoFunction
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoFunction}
|db._routing.save({
| url: "/hello/echo",
| action: {
| callback: "function(req,res) {res.statusCode=200; res.body='Hello'}"
| }
});
~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoFunction
!SUBSECTION Requests and Responses
The controller must define handler functions which take a request object and
@ -236,56 +240,44 @@ function (req, res, options, next) {
Install it via:
```js
arangosh> db._routing.save({
url: "/echo",
action: {
do: "org/arangodb/actions/echoRequest"
}
});
```
@startDocuBlockInline routingCreateEchoAction
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoAction}
|db._routing.save({
| url: "/echo",
| action: {
| do: "org/arangodb/actions/echoRequest"
| }
})
~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoAction
Reload the routing and check http:// 127.0.0.1:8529/hello/echo
You should see something like
```js
{
"request": {
"prefix": "/hello/echo",
"suffix": [
"hello",
"echo"
],
"path": "/hello/echo",
"headers": {
"accept-encoding": "gzip, deflate",
"accept-language": "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
"connection": "keep-alive",
"content-length": "0",
"host": "localhost:8529",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0"
},
"requestType": "GET",
"parameters": { }
},
"options": { }
}
```
@startDocuBlockInline fetchroutingRequestHelloEcho
@EXAMPLE_ARANGOSH_OUTPUT{fetchroutingRequestHelloEcho}
arango.GET("hello/echo")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock fetchroutingRequestHelloEcho
You may also pass options to the called function:
```js
arangosh> db._routing.save({
url: "/echo",
action: {
do: "org/arangodb/actions/echoRequest",
options: {
"Hello": "World"
}
}
});
```
@startDocuBlockInline routingCreateEchoRequestOptions
@EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoRequestOptions}
|db._routing.save({
| url: "/echo",
| action: {
| do: "org/arangodb/actions/echoRequest",
| options: {
| "Hello": "World"
| }
| }
});
~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoRequestOptions
You should now see the options in the result.
@ -298,4 +290,4 @@ You should now see the options in the result.
"Hello": "World"
}
}
````
````

View File

@ -2,31 +2,15 @@
By default, the ArangoDB shell uses a pretty printer when JSON documents are
printed. This ensures documents are printed in a human-readable way:
```js
arangosh> db.five.toArray();
[
{
"_id" : "five/3665447",
"_rev" : "3665447",
"name" : "one"
},
{
"_id" : "five/3730983",
"_rev" : "3730983",
"name" : "two"
},
{
"_id" : "five/3862055",
"_rev" : "3862055",
"name" : "four"
},
{
"_id" : "five/3993127",
"_rev" : "3993127",
"name" : "three"
}
]
```
@startDocuBlockInline usingToArray
@EXAMPLE_ARANGOSH_OUTPUT{usingToArray}
db._create("five")
for (i = 0; i < 5; i++) db.five.save({value:i})
db.five.toArray()
~db._drop("five");
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock usingToArray
While the pretty-printer produces nice looking results, it will need a lot of
screen space for each document. Sometimes, a more dense output might be better.

View File

@ -38,7 +38,14 @@ server after the password was entered.
To change the current database after the connection has been made, you
can use the `db._useDatabase()` command in arangosh:
arangosh> db._useDatabase("myapp");
@startDocuBlockInline shellUseDB
@EXAMPLE_ARANGOSH_OUTPUT{shellUseDB}
db._createDatabase("myapp");
db._useDatabase("myapp");
db._useDatabase("_system");
db._dropDatabase("myapp");
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock shellUseDB
To get a list of available commands, arangosh provides a *help()* function.
Calling it will display helpful information.
@ -54,20 +61,26 @@ current database.
For a list of available methods for the *db* object, type
arangosh> db._help();
@startDocuBlockInline shellHelp
@EXAMPLE_ARANGOSH_OUTPUT{shellHelp}
db._help();
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock shellHelp
you can paste multiple lines into arangosh, given the first line ends with an opening brace:
arangosh> for (var i = 0; i < 10; i ++) {
........> require("internal").print("Hello world " + i + "!\n");
........> }
Hello world 0!
<snip>
Hello world 9!
@startDocuBlockInline shellPaste
@EXAMPLE_ARANGOSH_OUTPUT{shellPaste}
|for (var i = 0; i < 10; i ++) {
| require("internal").print("Hello world " + i + "!\n");
}
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock shellPaste
To load your own javascript code into the current javascript interpreter context, use the load command:
require("internal").load("/tmp/test.js") // <- Linux / Macos
require("internal").load("c:\\tmp\\test.js") // <- Windows
Exiting arangosh can be done using the key combination ```<CTRL> + D```
Exiting arangosh can be done using the key combination ```<CTRL> + D``` or by typing ```quit<CR>```

View File

@ -12,17 +12,11 @@ fashion. The collection *_users* contains all users and a salted SHA256 hash
of their passwords. A user can be active or inactive. A typical document of this
collection is
```js
{
"_id" : "_users/1172449",
"_rev" : "1172449",
"_key" : "1172449",
"active" : true,
"changePassword" : false,
"user" : "root",
"password" : "$1$bd5458a8$8b23e2e1a762f75001ab182235b8ab1b8665bc572b0734a042a501b3c34e567a"
}
```
@startDocuBlockInline authFetch
@EXAMPLE_ARANGOSH_OUTPUT{authFetch}
db._users.toArray()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock authFetch
!SUBSECTION Command-Line Options for the Authentication and Authorization