You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> ArangoDB allows application developers to write their data access and domain logic as microservices running directly within the database with native access to in-memory data. The **Foxx microservice framework** makes it easy to extend ArangoDB’s own REST API with custom HTTP endpoints using modern JavaScript running on the same V8 engine you know from Node.js and the Google Chrome web browser.
3
4
>
4
5
> Unlike traditional approaches to storing logic in the database (like stored procedures), these microservices can be written as regular structured JavaScript applications that can be easily distributed and version controlled. Depending on your project’s needs Foxx can be used to build anything from optimized REST endpoints performing complex data access to entire standalone applications running directly inside the database.
@@ -14,17 +15,17 @@ So, instead of having complex logic describing complete API endpoint functionali
14
15
1.`git clone` the whole thing, and you are good to go.
In package.json in *scripts* section you will find a number of shortcuts that will help you register your server with foxx-cli, and install or replace Foxx microservice on your server.
21
+
In the `package.json` in the *scripts* section, you will find a number of shortcuts that will help you register your server with `foxx-cli`, and install or replace the Foxx microservice on your server.
21
22
22
-
2. Install foxx-cli if you don't have it yet [https://github.com/arangodb/foxx-cli#install](https://github.com/arangodb/foxx-cli#install)
23
+
2. Install `foxx-cli` if you don't have it yet [https://github.com/arangodb/foxx-cli#install](https://github.com/arangodb/foxx-cli#install)
23
24
24
25
3. Register your ArangoDB server so you can install and replace your Foxx Microservices, for example:
25
26
26
27
```sh
27
-
$foxx server set dev http://dev:sandbox@localhost:8529
28
+
foxx server set dev http://dev:sandbox@localhost:8529
28
29
```
29
30
30
31
By executing this command, we assume that you already created a user _dev_ with password _sandbox_ on _localhost_ server, and we register this server to foxx-cli as _dev_.
@@ -40,25 +41,28 @@ This file contains sections for each server which may contain server credentials
40
41
4. The example below shows how you can install this Foxx Microservice on _dev_ server to _dev_ database and mount it as _/api_ endpoint.
41
42
42
43
```sh
43
-
$foxx install /api . --server dev --database dev
44
+
foxx install /api . --server dev --database dev
44
45
```
45
46
46
47
### Folder Structure
47
48
48
-
There are very few bits required to make your foxx services up and running. The folder structure defined in a way that will help you to have better control over API application architecture with a minimal coding effort from your side.
49
+
There are very few bits required to make your foxx services up and running. The folder structure is defined in a way that will help you to have better control over API application architecture with a minimal coding effort from your side.
49
50
50
51
```
51
-
/builder/
52
-
/foxx/
52
+
src/
53
+
--/builder/
54
+
---- context-extensions.js
55
+
---- index
56
+
--/foxx/
57
+
-- index.js
58
+
-- setup.js
53
59
manifest.json
54
60
package.json
55
-
index.js
56
-
setup.js
57
61
```
58
62
59
-
_/builder_ is the actual Foxx Builder service with all its utils
63
+
_/builder_ is the actual Foxx Builder service with all its utils. Unless you want to modify how `foxx-builder` works, you don't need to touch it.
60
64
61
-
_/foxx_ is the folder where you will create your API service handlers with convention described below;
65
+
_/foxx_ is the folder where you will create your API service handlers with the convention described below;
62
66
63
67
_manifest.json_ is a Service Manifest file, as described on https://www.arangodb.com/docs/stable/foxx-reference-manifest.html;
64
68
@@ -89,19 +93,19 @@ To handle this case, we will add to _foxx_ folder our handler in this way:
89
93
90
94
```
91
95
/foxx/
92
-
--/echo/
93
-
----all.js
96
+
--/echo/
97
+
----all.js
94
98
```
95
99
96
100
Another example - we need to add a ```/api/users``` route that on _GET_ method will reply with some data and on _POST_ will accept data sent to API and then respond.
97
101
98
102
```
99
103
/foxx
100
-
--/echo
101
-
----all.js
102
-
--/users
103
-
----post.js
104
-
----post.js
104
+
--/echo
105
+
----all.js
106
+
--/users
107
+
----post.js
108
+
----post.js
105
109
```
106
110
107
111
In other words, file path your API route method handler mirrors your URL path
@@ -124,16 +128,16 @@ Adding parameters to your URL point handling is pretty simple. Probably, you alr
124
128
125
129
```
126
130
/foxx/
127
-
--/users/
128
-
----post.js
129
-
----post.js
130
-
----/$id/
131
-
------post.js
131
+
--/users/
132
+
----post.js
133
+
----post.js
134
+
----/$id/
135
+
------post.js
132
136
------/tasks/
133
-
--------post.js
134
-
--------post.js
135
-
--------/$task/
136
-
----------post.js
137
+
--------post.js
138
+
--------post.js
139
+
--------/$task/
140
+
----------post.js
137
141
```
138
142
139
143
More on path parameters you can read on [https://www.arangodb.com/docs/stable/foxx-getting-started.html#parameter-validation](https://www.arangodb.com/docs/stable/foxx-getting-started.html#parameter-validation).
Now, on every request, we will receive a message in our Telegram Channel. You can use it, for example, for logging into channel any debug data or stack trace from exceptions fired by your API. Telegram `sendMessage` params are documented at[Telegram Bot API](https://core.telegram.org/bots/api#sendmessage) web page.
275
+
Now, on every request, we will receive a message on our Telegram Channel. You can use it, for example, for logging into the channel any debug data or stack trace from exceptions fired by your API. Telegram `sendMessage` params are documented on the[Telegram Bot API](https://core.telegram.org/bots/api#sendmessage) web page.
In `Foxx-builder` v.2.x, we added `docker-compose.yml` file and a few shortcuts into `package.json` that will help you to develop your APIs and run them in docker. You can use `npm` or `yarn` in order to run things, just keep in mind that there is an order of actions to take into consideration,
300
+
301
+
The flow would be like this:
302
+
303
+
1. Start docker container: `yarn run docker:start`
304
+
2. Setup the development database `yarn run docker:setup-db`
305
+
3. Register development database server with Foxx CLI `yarn run register-foxx-dev-server`
306
+
4. Install Foxx Microservices on `/api` endpoint on development database `yarn run install-foxx-dev`
307
+
308
+
After microservices are installed, during the development, all you will need to call is a `replace` method - `yarn run replace-foxx-dev`
309
+
310
+
311
+
312
+
## Testing Foxx Services APIs
313
+
314
+
You use [Hurl](https://hurl.dev) to test your API endpoints.
315
+
316
+
> Hurl is a command-line tool that runs **HTTP requests** defined in a simple **plain text format**.
317
+
>
318
+
> It can perform requests, capture values, and evaluate queries on headers and body responses. Hurl is very versatile: it can be used for both **fetching data** and **testing HTTP** sessions.
319
+
320
+
There are two ways you can run hurl tests, - via the docker container or by having hurl installed.
0 commit comments