Skip to the content.

Route API

Route instances provide access for arbitrary HTTP requests. This allows easy access to Foxx services and other HTTP APIs not covered by the driver itself.

route.route

route.route([path], [headers]): Route

Returns a new Route instance for the given path (relative to the current route) that can be used to perform arbitrary HTTP requests.

Arguments

If path is missing, the route will refer to the base URL of the database.

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const users = route.route("users");
// equivalent to db.route('my-foxx-service/users')

route.get

async route.get([path,] [qs]): Response

Performs a GET request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.get();
// response.body is the response body of calling
// GET _db/_system/my-foxx-service

// -- or --

const response = await route.get("users");
// response.body is the response body of calling
// GET _db/_system/my-foxx-service/users

// -- or --

const response = await route.get("users", { group: "admin" });
// response.body is the response body of calling
// GET _db/_system/my-foxx-service/users?group=admin

route.post

async route.post([path,] [body, [qs]]): Response

Performs a POST request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.post();
// response.body is the response body of calling
// POST _db/_system/my-foxx-service

// -- or --

const response = await route.post("users");
// response.body is the response body of calling
// POST _db/_system/my-foxx-service/users

// -- or --

const response = await route.post("users", {
  username: "admin",
  password: "hunter2"
});
// response.body is the response body of calling
// POST _db/_system/my-foxx-service/users
// with JSON request body {"username": "admin", "password": "hunter2"}

// -- or --

const response = await route.post(
  "users",
  {
    username: "admin",
    password: "hunter2"
  },
  { admin: true }
);
// response.body is the response body of calling
// POST _db/_system/my-foxx-service/users?admin=true
// with JSON request body {"username": "admin", "password": "hunter2"}

route.put

async route.put([path,] [body, [qs]]): Response

Performs a PUT request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.put();
// response.body is the response body of calling
// PUT _db/_system/my-foxx-service

// -- or --

const response = await route.put("users/admin");
// response.body is the response body of calling
// PUT _db/_system/my-foxx-service/users

// -- or --

const response = await route.put("users/admin", {
  username: "admin",
  password: "hunter2"
});
// response.body is the response body of calling
// PUT _db/_system/my-foxx-service/users/admin
// with JSON request body {"username": "admin", "password": "hunter2"}

// -- or --

const response = await route.put(
  "users/admin",
  {
    username: "admin",
    password: "hunter2"
  },
  { admin: true }
);
// response.body is the response body of calling
// PUT _db/_system/my-foxx-service/users/admin?admin=true
// with JSON request body {"username": "admin", "password": "hunter2"}

route.patch

async route.patch([path,] [body, [qs]]): Response

Performs a PATCH request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.patch();
// response.body is the response body of calling
// PATCH _db/_system/my-foxx-service

// -- or --

const response = await route.patch("users/admin");
// response.body is the response body of calling
// PATCH _db/_system/my-foxx-service/users

// -- or --

const response = await route.patch("users/admin", {
  password: "hunter2"
});
// response.body is the response body of calling
// PATCH _db/_system/my-foxx-service/users/admin
// with JSON request body {"password": "hunter2"}

// -- or --

const response = await route.patch(
  "users/admin",
  {
    password: "hunter2"
  },
  { admin: true }
);
// response.body is the response body of calling
// PATCH _db/_system/my-foxx-service/users/admin?admin=true
// with JSON request body {"password": "hunter2"}

route.delete

async route.delete([path,] [qs]): Response

Performs a DELETE request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.delete();
// response.body is the response body of calling
// DELETE _db/_system/my-foxx-service

// -- or --

const response = await route.delete("users/admin");
// response.body is the response body of calling
// DELETE _db/_system/my-foxx-service/users/admin

// -- or --

const response = await route.delete("users/admin", { permanent: true });
// response.body is the response body of calling
// DELETE _db/_system/my-foxx-service/users/admin?permanent=true

route.head

async route.head([path,] [qs]): Response

Performs a HEAD request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.head();
// response is the response object for
// HEAD _db/_system/my-foxx-service

route.request

async route.request([opts]): Response

Performs an arbitrary request to the given URL and returns the server response.

Arguments

Examples

const db = new Database();
const route = db.route("my-foxx-service");
const response = await route.request({
  path: "hello-world",
  method: "POST",
  body: { hello: "world" },
  qs: { admin: true }
});
// response.body is the response body of calling
// POST _db/_system/my-foxx-service/hello-world?admin=true
// with JSON request body '{"hello": "world"}'