Foxx http.request() like in Node.JS

173 views
Skip to first unread message

Bogdan P.

unread,
Jan 5, 2014, 7:27:07 AM1/5/14
to aran...@googlegroups.com
Hello,

Is there a way to make external http calls from within a foxx controller? I'm thinking something like the http.request() in node.js. I need my foxx app to connect a 3rd party rest service. 

Best regards,
Bogdan Popa

Michael Hackstein

unread,
Jan 5, 2014, 4:27:05 PM1/5/14
to aran...@googlegroups.com
Hi Bogdan,

there is a function in our "internal" module for this, which we use e.g. for downloading foxx apps from their github repository.

You have two options in your Foxx Controller:
1)

  var internal = require("internal");
  internal.download(url, body, options, path-to-outfile);

Replace the url and body accordingly.
The body of the answer will be written to outfile.
Options is a JSON object to define header options e.g. {"method": "GET"}

2)

  var internal = require("internal");
  var result = internal.download(url, body, options);

result will then contain the complete result (including: headers, body, status etc.)


hope that helps,

best
Michael


--
You received this message because you are subscribed to the Google Groups "ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arangodb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bogdan P.

unread,
Jan 6, 2014, 5:30:18 AM1/6/14
to aran...@googlegroups.com
That's great. Thank you! 

Patrick Mulder

unread,
Jan 7, 2014, 4:27:47 AM1/7/14
to aran...@googlegroups.com
Just thinking on this, and maybe it would be nice to have a general purpose, public RESTful client in Foxx too.
For example, if a new users signs up (is created in ArangoDB), and we would like to send an email. In this case, something like the Mailchimp or Mailgun API might be called to send the actual email out, or?

Lucas Dohmen

unread,
Jan 8, 2014, 3:53:17 AM1/8/14
to aran...@googlegroups.com
Hi Patrick,

The functionality of calling external services will be enhanced in the next version of Foxx. We will use a job queue where you can add calls to external APIs. I will provide more details about that in March :)

Best Wishes
Lucas
signature.asc

Karan Kapur

unread,
Nov 20, 2017, 1:52:04 AM11/20/17
to ArangoDB
How can we call a url with basic authentication using internal module 'download' function?

Karan Kapur

unread,
Nov 20, 2017, 2:14:32 AM11/20/17
to ArangoDB
"code": 400, "message": "Bad Request", "headers": { "connection": "keep-alive", "content-length": "163", "x-found-handling-server": "10.145.194.175", "x-found-handling-instance": "instance-0000000004", "server": "fp/43e8d0", "http/1.1": "400 Bad Request", "x-found-handling-cluster": "f99b5b6a08b843b17ccf3507723a1ac8", "date": "Mon, 20 Nov 2017 07:11:49 GMT", "content-type": "application/json; charset=UTF-8"

Getting this error for elastic cloud url

https://f99b5b6a08b843b17ccf3507723a1ac8.us-east-1.aws.found.io:9243/arango/error

Its working fine on postman though;

Wilfried Gösgens

unread,
Nov 21, 2017, 8:26:45 AM11/21/17
to ArangoDB
Hi,
most probably the quickest way to achieve this is to set the `WWW-Authenticate`-header for auth/basic authentification as documented here:
https://en.wikipedia.org/wiki/Basic_access_authentication

Cheers,
Willi
Reply all
Reply to author
Forward
0 new messages