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. If you change the example slightly, then a JSON object will be delivered.
```js @startDocuBlockInline routingCreateHelloWorld
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateHelloWorld}
url: "/hello/json", |db._routing.save({
content: { | url: "/hello/json",
contentType: "application/json", | content: {
body: "{ \"hello\" : \"world\" }" | contentType: "application/json",
} | body: "{ \"hello\" : \"world\" }"
| }
}); });
arangosh> require("internal").reloadRouting() require("internal").reloadRouting()
``` @END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateHelloWorld
Again check with your browser http:// localhost:8529/hello/json 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 *"text/plain"* for the example. This makes it easier to check the example using
a browser. Or use *curl* to access the server. a browser. Or use *curl* to access the server.
```js @startDocuBlockInline routingCurlHelloWorld
bash> curl "http://127.0.0.1:8529/hello/json" && echo @EXAMPLE_ARANGOSH_RUN{routingCurlHelloWorld}
{ "hello" : "world" } var url = "/hello/json";
``` var response = logCurlRequest('GET', url);
assert(response.code === 200);
logJsonResponse(response);
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCurlHelloWorld
!SECTION Delivering Content !SECTION Delivering Content
@ -83,37 +90,27 @@ function (req, res, options, next)
*Examples* *Examples*
```js @startDocuBlockInline routingCreateHelloEcho
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateHelloEcho}
url: "/hello/echo", |db._routing.save({
action: { | url: "/hello/echo",
do: "org/arangodb/actions/echoRequest" | 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 Reload the routing and check http:// 127.0.0.1:8529/hello/echo
You should see something like You should see something like
```js @startDocuBlockInline fetchroutingCreateHelloEcho
{ @EXAMPLE_ARANGOSH_OUTPUT{fetchroutingCreateHelloEcho}
"request": { arango.GET("hello/echo")
"path": "/hello/echo", @END_EXAMPLE_ARANGOSH_OUTPUT
"headers": { @endDocuBlock fetchroutingCreateHelloEcho
"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": { }
}
```
The request might contain *path*, *prefix*, *suffix*, and *urlParameters* The request might contain *path*, *prefix*, *suffix*, and *urlParameters*
attributes. *path* is the complete path as supplied by the user and always attributes. *path* is the complete path as supplied by the user and always
@ -151,14 +148,17 @@ called.
*Examples* *Examples*
```js @startDocuBlockInline routingCreateEchoController
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoController}
url: "/hello/echo", |db._routing.save({
action: { | url: "/hello/echo",
controller: "org/arangodb/actions/echoController" | action: {
} | controller: "org/arangodb/actions/echoController"
| }
}); });
``` ~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoController
!SUBSECTION Prefix Action Controller !SUBSECTION Prefix Action Controller
@ -206,14 +206,18 @@ You can also store a function directly in the routing table.
*Examples* *Examples*
```js @startDocuBlockInline routingCreateEchoFunction
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoFunction}
url: "/hello/echo", |db._routing.save({
action: { | url: "/hello/echo",
callback: "function(req,res) {res.statusCode=200; res.body='Hello'}" | action: {
} | callback: "function(req,res) {res.statusCode=200; res.body='Hello'}"
| }
}); });
``` ~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoFunction
!SUBSECTION Requests and Responses !SUBSECTION Requests and Responses
The controller must define handler functions which take a request object and The controller must define handler functions which take a request object and
@ -236,56 +240,44 @@ function (req, res, options, next) {
Install it via: Install it via:
```js @startDocuBlockInline routingCreateEchoAction
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoAction}
url: "/echo", |db._routing.save({
action: { | url: "/echo",
do: "org/arangodb/actions/echoRequest" | 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 Reload the routing and check http:// 127.0.0.1:8529/hello/echo
You should see something like You should see something like
```js @startDocuBlockInline fetchroutingRequestHelloEcho
{ @EXAMPLE_ARANGOSH_OUTPUT{fetchroutingRequestHelloEcho}
"request": { arango.GET("hello/echo")
"prefix": "/hello/echo", @END_EXAMPLE_ARANGOSH_OUTPUT
"suffix": [ @endDocuBlock fetchroutingRequestHelloEcho
"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": { }
}
```
You may also pass options to the called function: You may also pass options to the called function:
```js @startDocuBlockInline routingCreateEchoRequestOptions
arangosh> db._routing.save({ @EXAMPLE_ARANGOSH_OUTPUT{routingCreateEchoRequestOptions}
url: "/echo", |db._routing.save({
action: { | url: "/echo",
do: "org/arangodb/actions/echoRequest", | action: {
options: { | do: "org/arangodb/actions/echoRequest",
"Hello": "World" | options: {
} | "Hello": "World"
} | }
| }
}); });
``` ~require("internal").reloadRouting()
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock routingCreateEchoRequestOptions
You should now see the options in the result. You should now see the options in the result.

View File

@ -2,31 +2,15 @@
By default, the ArangoDB shell uses a pretty printer when JSON documents are By default, the ArangoDB shell uses a pretty printer when JSON documents are
printed. This ensures documents are printed in a human-readable way: printed. This ensures documents are printed in a human-readable way:
```js
arangosh> db.five.toArray(); @startDocuBlockInline usingToArray
[ @EXAMPLE_ARANGOSH_OUTPUT{usingToArray}
{ db._create("five")
"_id" : "five/3665447", for (i = 0; i < 5; i++) db.five.save({value:i})
"_rev" : "3665447", db.five.toArray()
"name" : "one" ~db._drop("five");
}, @END_EXAMPLE_ARANGOSH_OUTPUT
{ @endDocuBlock usingToArray
"_id" : "five/3730983",
"_rev" : "3730983",
"name" : "two"
},
{
"_id" : "five/3862055",
"_rev" : "3862055",
"name" : "four"
},
{
"_id" : "five/3993127",
"_rev" : "3993127",
"name" : "three"
}
]
```
While the pretty-printer produces nice looking results, it will need a lot of 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. 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 To change the current database after the connection has been made, you
can use the `db._useDatabase()` command in arangosh: 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. To get a list of available commands, arangosh provides a *help()* function.
Calling it will display helpful information. Calling it will display helpful information.
@ -54,20 +61,26 @@ current database.
For a list of available methods for the *db* object, type 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: you can paste multiple lines into arangosh, given the first line ends with an opening brace:
arangosh> for (var i = 0; i < 10; i ++) { @startDocuBlockInline shellPaste
........> require("internal").print("Hello world " + i + "!\n"); @EXAMPLE_ARANGOSH_OUTPUT{shellPaste}
........> } |for (var i = 0; i < 10; i ++) {
Hello world 0! | require("internal").print("Hello world " + i + "!\n");
<snip> }
Hello world 9! @END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock shellPaste
To load your own javascript code into the current javascript interpreter context, use the load command: 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("/tmp/test.js") // <- Linux / Macos
require("internal").load("c:\\tmp\\test.js") // <- Windows 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 of their passwords. A user can be active or inactive. A typical document of this
collection is collection is
```js @startDocuBlockInline authFetch
{ @EXAMPLE_ARANGOSH_OUTPUT{authFetch}
"_id" : "_users/1172449", db._users.toArray()
"_rev" : "1172449", @END_EXAMPLE_ARANGOSH_OUTPUT
"_key" : "1172449", @endDocuBlock authFetch
"active" : true,
"changePassword" : false,
"user" : "root",
"password" : "$1$bd5458a8$8b23e2e1a762f75001ab182235b8ab1b8665bc572b0734a042a501b3c34e567a"
}
```
!SUBSECTION Command-Line Options for the Authentication and Authorization !SUBSECTION Command-Line Options for the Authentication and Authorization