Skip to content

Commit 01dc5af

Browse files
committed
chore: updated documentation
1 parent 2b153be commit 01dc5af

File tree

2 files changed

+89
-32
lines changed

2 files changed

+89
-32
lines changed

README.md

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# foxx-builder
2+
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/skitsanos/foxx-builder/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/skitsanos/foxx-builder/tree/master)
23
> 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.
34
>
45
> 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
1415
1. `git clone` the whole thing, and you are good to go.
1516

1617
```sh
17-
$git clone https://github.com/skitsanos/foxx-builder.git
18+
git clone https://github.com/skitsanos/foxx-builder.git
1819
```
1920

20-
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.
2122

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)
2324

2425
3. Register your ArangoDB server so you can install and replace your Foxx Microservices, for example:
2526

2627
```sh
27-
$foxx server set dev http://dev:sandbox@localhost:8529
28+
foxx server set dev http://dev:sandbox@localhost:8529
2829
```
2930

3031
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
4041
4. The example below shows how you can install this Foxx Microservice on _dev_ server to _dev_ database and mount it as _/api_ endpoint.
4142

4243
```sh
43-
$foxx install /api . --server dev --database dev
44+
foxx install /api . --server dev --database dev
4445
```
4546

4647
### Folder Structure
4748

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.
4950

5051
```
51-
/builder/
52-
/foxx/
52+
src/
53+
--/builder/
54+
---- context-extensions.js
55+
---- index
56+
--/foxx/
57+
-- index.js
58+
-- setup.js
5359
manifest.json
5460
package.json
55-
index.js
56-
setup.js
5761
```
5862

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.
6064

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;
6266

6367
_manifest.json_ is a Service Manifest file, as described on https://www.arangodb.com/docs/stable/foxx-reference-manifest.html;
6468

@@ -89,19 +93,19 @@ To handle this case, we will add to _foxx_ folder our handler in this way:
8993

9094
```
9195
/foxx/
92-
--/echo/
93-
----all.js
96+
-- /echo/
97+
---- all.js
9498
```
9599

96100
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.
97101

98102
```
99103
/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
105109
```
106110

107111
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
124128

125129
```
126130
/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
132136
------/tasks/
133-
--------post.js
134-
--------post.js
135-
--------/$task/
136-
----------post.js
137+
-------- post.js
138+
-------- post.js
139+
-------- /$task/
140+
---------- post.js
137141
```
138142

139143
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).
@@ -268,7 +272,7 @@ module.context.use((req, res, next) =>
268272
});
269273
```
270274

271-
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.
272276

273277
### Session Management
274278

@@ -290,6 +294,59 @@ sessions.allowedResources = [
290294
sessions.init();
291295
```
292296

297+
## Developing on Docker
298+
299+
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.
321+
322+
Testing with `hurl` running in docker:
323+
324+
```shell
325+
docker run --network host --rm -it -v "$(pwd)/.api-test":/app "orangeopensource/hurl:latest" --test --variables-file /app/.vars /app/hello.hurl
326+
```
327+
328+
Or, if you already have `hurl` installed ([Installation instructions](https://hurl.dev/docs/installation.html))
329+
330+
```shell
331+
hurl --test --variables-file .api-test/.vars .api-test/*.hurl
332+
```
333+
334+
`.vars` file contains variables needed for your tests and can look like this:
335+
336+
```
337+
URL=http://localhost:8529/_db/dev/api
338+
```
339+
340+
So, all together with variables, you can make an API test that will check if your API is up:
341+
342+
```
343+
GET {{URL}}/
344+
345+
HTTP/* 200
346+
```
347+
348+
The `{{URL}}` referres to `URL` variable from `.vars` file.
349+
293350

294351

295352
## Integrations
@@ -300,7 +357,7 @@ sessions.init();
300357

301358
#### netlify.toml example configuration
302359

303-
In case if you are using Netlify, here is the example for you how to proxy your URL API calls to ArangoDB Microservices.
360+
In case you are using Netlify, here is an example of how to proxy your URL API calls to ArangoDB Microservices.
304361

305362
```toml
306363
[build]
@@ -332,5 +389,5 @@ Before deploying it on Netlify, make sure there are two variables replaced:
332389
- {YOUR_HOSTNAME} - the hostname where ArangoDb is running
333390
- {YOUR_ENDPOINT} - endpoint where your flex services are mounted
334391

335-
Also please refer to [Exposing Foxx to the browser](https://www.arangodb.com/docs/stable/foxx-guides-browser.html) on ArangoDB documentation web site.
392+
Also please refer to [Exposing Foxx to the browser](https://www.arangodb.com/docs/stable/foxx-guides-browser.html) on ArangoDB documentation website.
336393

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"register-foxx-dev-server": "foxx server set dev http://dev:sandbox@localhost:8529",
1515
"install-foxx-dev": "foxx install /api . --server dev --database dev",
1616
"replace-foxx-dev": "foxx replace /api . --server dev --database dev",
17-
"test": "docker run --network host --rm -it -v \"$(pwd)/.api-test\":/app \"orangeopensource/hurl:latest\" --test --variables-file /app/.vars /app/hello.hurl"
17+
"test": "docker run --network host --rm -it -v \"$(pwd)/.api-test\":/app \"orangeopensource/hurl:latest\" --test --variables-file /app/.vars /app/*.hurl"
1818
},
1919
"dependencies": {}
2020
}

0 commit comments

Comments
 (0)