Making requests

ArangoDB is primarily a database, so Foxx doesn’t offer the same level of network access as more general-purpose JavaScript environments like Node.js. However ArangoDB does provide the @arangodb/request module for making HTTP (or HTTPS) requests:

  1. "use strict";
  2. const request = require("@arangodb/request");
  3. const response = request.get(
  4. "https://pokeapi.co/api/v2/pokemon/25/"
  5. );
  6. if (response.status < 400) {
  7. const pikachu = response.json;
  8. console.log(pikachu);
  9. }

Because Foxx services are always synchronous and network requests can be considerably slower than any other database operation, you should avoid making requests in your service if possible or use queues instead.

By using an absolute path instead of a full URL, you can also use the request module to talk to ArangoDB itself, for example in integration tests:

  1. const response = request.get("/_db/_system/myfoxx/something");

Note: Although making local requests doesn’t create the network overhead as making requests to other servers, special care needs to be taken when talking to services on the same server. If you want to connect services in the same database you should use dependencies instead.