Making requests

ArangoDB is primarily a database, so Foxx doesn’t offer the same level ofnetwork access as more general-purpose JavaScript environments like Node.js.However ArangoDB does provide the@arangodb/request modulefor 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. }

BecauseFoxx services are always synchronousand network requests can be considerably slower than any otherdatabase operation, you should avoid making requests in your serviceif possible or use queues instead.

By using an absolute path instead of a full URL, you can also use therequest 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 overheadas making requests to other servers, special care needs to be taken whentalking to services on the same server. If you want to connect servicesin the same database you should use dependencies instead.