HTTP request to external web service

159 views
Skip to first unread message

kme...@minerva-group.com

unread,
Jun 18, 2013, 4:12:31 PM6/18/13
to moch...@googlegroups.com
I have a HTTP server using mochiweb and I would like it to do an HTTP request to an external web service, wait for the result, do something with it, and then return a HTTP response.

How would you approach this situation in mochiweb?

In my case I would like to leverage data from the Amazon Advertising API, using the amazonproductapi library ( https://github.com/arjan/amazonproductapi )

Bob Ippolito

unread,
Jun 18, 2013, 4:27:17 PM6/18/13
to moch...@googlegroups.com
I think you've described the solution pretty well. Just use a HTTP client library to make the request to the external service and do whatever it is you need to do with the response. The fact that you're also using mochiweb is irrelevant. 
--
You received this message because you are subscribed to the Google Groups "MochiWeb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mochiweb+u...@googlegroups.com.
To post to this group, send email to moch...@googlegroups.com.
Visit this group at http://groups.google.com/group/mochiweb.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

kme...@minerva-group.com

unread,
Jun 19, 2013, 5:45:16 PM6/19/13
to moch...@googlegroups.com
When I am using the amazonproductapi to make a request, I am getting the following crash:

=CRASH REPORT==== 19-Jun-2013::17:32:50 ===
  crasher:
    initial call: mochiweb_acceptor:init/3
    pid: <0.104.0>
    registered_name: []
    exception exit: {noproc,
                     {gen_server,call,
                      [httpc_manager,
                       {request,
                        {request,undefined,<0.104.0>,0,http,
                         {"webservices.amazon.com",80},
                         "/onca/xml",
                         "?
                         get,
                         {http_request_h,undefined,"keep-alive",undefined,
                          undefined,undefined,undefined,undefined,undefined,
                          undefined,undefined,undefined,undefined,undefined,
                          undefined,undefined,undefined,
                          "webservices.amazon.com",undefined,undefined,
                          undefined,undefined,undefined,undefined,undefined,
                          undefined,undefined,[],undefined,undefined,
                          undefined,undefined,"0",undefined,undefined,
                          undefined,undefined,undefined,undefined,[]},
                         {[],[]},
                         {http_options,"HTTP/1.1",infinity,true,
                          {essl,[]},
                          undefined,false,infinity,false},
                         "http://webservices.amazon.com/onca/xml?
                         [],none,[],1371677570196,undefined,undefined,false}},
                       infinity]}}
      in function  gen_server:call/3 (gen_server.erl, line 188)
      in call from httpc:handle_request/9 (httpc.erl, line 584)
      in call from amazonproductapi:do_rest_call/4 (src/amazonproductapi.erl, line 65)
      in call from isbn_imageserver:handle_test/2 (src/isbn_imageserver.erl, line 86)
      in call from mochiweb_http:headers/5 (src/mochiweb_http.erl, line 101)
    ancestors: [mochiweb_http,isbn_imageserver_sup,<0.30.0>]


and the call was as following: amazonproductapi:itemSearch(Isbn, ?A_CONFIG) % where ?A_CONFIG is the API config object

This only happens when I run this inside of my mochiweb server, not when I run this from the console.

Do you have any ideas why this is happening? I cannot start a lot with the crash report.

On Tuesday, June 18, 2013 4:27:17 PM UTC-4, Bob Ippolito wrote:
I think you've described the solution pretty well. Just use a HTTP client library to make the request to the external service and do whatever it is you need to do with the response. The fact that you're also using mochiweb is irrelevant. 

On Tuesday, June 18, 2013, wrote:
I have a HTTP server using mochiweb and I would like it to do an HTTP request to an external web service, wait for the result, do something with it, and then return a HTTP response.

How would you approach this situation in mochiweb?

In my case I would like to leverage data from the Amazon Advertising API, using the amazonproductapi library ( https://github.com/arjan/amazonproductapi )

--
You received this message because you are subscribed to the Google Groups "MochiWeb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mochiweb+unsubscribe@googlegroups.com.

Jon Watte

unread,
Jun 19, 2013, 5:51:36 PM6/19/13
to moch...@googlegroups.com
Mochiweb doesn't have a HTTP client library in itself. OTP does, though.

When using R13, the HTTP client available in OTP wasn't particularly robust -- it failed for our case (I think the problem was multiple overlapping requests got confused, IIRC.)

I don't know if that's been fixed since then, but we ended up implementing our own HTTP client for the kinds of requests we needed.

Sincerely,

jw






Sincerely,

Jon Watte


--
"I pledge allegiance to the flag of the United States of America, and to the republic for which it stands, one nation indivisible, with liberty and justice for all."
~ Adopted by U.S. Congress, June 22, 1942


--
You received this message because you are subscribed to the Google Groups "MochiWeb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mochiweb+u...@googlegroups.com.

Kenny Meyer

unread,
Jun 19, 2013, 5:54:58 PM6/19/13
to moch...@googlegroups.com
I don't know if that's been fixed since then, but we ended up implementing our own HTTP client for the kinds of requests we needed.
How do you use it? Can you show me some code?


--
You received this message because you are subscribed to a topic in the Google Groups "MochiWeb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mochiweb/c_dKJtX8gT0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mochiweb+u...@googlegroups.com.

To post to this group, send email to moch...@googlegroups.com.
Visit this group at http://groups.google.com/group/mochiweb.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Bob Ippolito

unread,
Jun 19, 2013, 6:14:45 PM6/19/13
to moch...@googlegroups.com
This is the error that you get from httpc if you haven't started the inets application. If you start the inets application, this will probably work just fine.


To unsubscribe from this group and stop receiving emails from it, send an email to mochiweb+u...@googlegroups.com.

Kenny Meyer

unread,
Jun 19, 2013, 6:29:17 PM6/19/13
to moch...@googlegroups.com
Thanks Bob, that fixed it. I have picked up Erlang a week ago, so there's still a lot I don't know.

Feeling much better now :)


You received this message because you are subscribed to a topic in the Google Groups "MochiWeb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mochiweb/c_dKJtX8gT0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mochiweb+u...@googlegroups.com.

To post to this group, send email to moch...@googlegroups.com.
Visit this group at http://groups.google.com/group/mochiweb.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Bob Ippolito

unread,
Jun 19, 2013, 6:34:08 PM6/19/13
to moch...@googlegroups.com
It takes a little time to learn how to read those error messages. When I look at this error message I see a {noproc, {gen_server, call, _}} exit, which always means that you're trying to call a server that isn't currently running. This typically means that you haven't started all of the applications that your app depends on.
Reply all
Reply to author
Forward
0 new messages