Skip to content

Getting Started

Skitsanos edited this page Jan 22, 2023 · 2 revisions

First, you will need to download the latest version of Foxx Builder from this repo or clone it into your own since we provide it as a template repo. Once you have it downloaded, you can create a new project by creating a new folder and adding the following basic structure:

myproject/
--/src/
----/routes/
------/users/
---- index.js
---- setup.js
-- manifest.json
-- package.json

In this structure, the '/routes' folder is where you will define all your API service handlers. Each service handler is a JavaScript file that maps to an HTTP verb (GET, POST, PUT, DELETE). For example, if you want to handle a GET request for the '/users' endpoint, you would create a 'get.js' file in the '/routes/users' folder. Please refer to Routes page for more details on creating endpoints handlers.

index.js

The 'index.js' file is the entry point for your service, and the 'setup.js' file is used for any setup tasks that need to be performed before your service starts. The 'manifest.json' file is a Service Manifest file, as described on https://www.arangodb.com/docs/stable/foxx-reference-manifest.html.

setup.js

The setup.js script is a script that runs when a Foxx service is first installed on an ArangoDB server. It can perform any necessary setup tasks, such as creating collections or populating initial data, before making the service available to clients. This script is executed only once when the service is first installed. The setup.js script can perform any necessary setup tasks, such as creating collections or populating initial data, before making the service available to clients. It can also be used to check for dependencies or perform any additional setup tasks needed to get the service running.

manifest.json

The manifest.json file is a Service Manifest file, which defines metadata and configuration information for a Foxx service. This file is required for every Foxx service and must be located in the root of the service's directory. The manifest file contains information such as the service's name, version, author, and dependencies. It also defines the service's routes, configuration options, and scripts that run during certain events, such as when the service is started or stopped. The ArangoDB Foxx service manager uses the information in the manifest file to manage the service, such as to start, stop, or update it. The manifest file is also used to generate documentation for the service and its API.

Once your project structure is set up, you can start defining your service handlers in the '/routes' folder. Each handler should export a JavaScript object with properties such as 'contentType', 'name', 'body', and 'handler'. The 'handler' property is a function that will be executed when the endpoint is called.

You can use Foxx Builder's context extensions to easily create, read, update, and delete documents in your database. With Foxx Builder, you can focus on building your service logic, and let the framework handle the rest.

To deploy your service, you can use the Foxx CLI to install it in your ArangoDB instance. Once installed, you can start using your API service immediately.

Clone this wiki locally