# Notify a web-service: sending non-blocking http requests

**URL:** <https://rubytalk.org/t/notify-a-web-service-sending-non-blocking-http-requests/43256>\
**Category:** ruby-talk\
**Created:** [24 December 2007 12:47 UTC](https://rubytalk.org/t/notify-a-web-service-sending-non-blocking-http-requests/43256 "2007-12-24T12:47:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Collier](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Collier](https://rubytalk.org/u/David_Collier)\
**Post date:** [24 December 2007 12:47 UTC](https://rubytalk.org/t/notify-a-web-service-sending-non-blocking-http-requests/43256/1 "2007-12-24T12:47:29Z")

</div>

hi -

i want to notify a webservice of something, but not wait for the  
response. whats the best way to do this?

is there a way to use a GET call to just send a request and then continue?

i could use the timeout library i guess with a timeout of 0 ? which i  
guess spawns a thread...

or use  
&nbsp;&nbsp;system("curl #{url}")

but this seems like a lot of overhead.

is there a UDP package for ruby?  
i guess another hack might be to return a page to the user with a GIF  
image with a URL of the service i want to request,  
then it will take no resources from my system...  
&nbsp;&nbsp;\<img width=1 height=1 src='[http://server/notify/event](http://server/notify/event)" /\>

tx

/dc

---

<div class="post-metadata">

**Author:** ![Curt\_Sampson](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Curt\_Sampson](https://rubytalk.org/u/Curt_Sampson)\
**Post date:** [24 December 2007 13:33 UTC](https://rubytalk.org/t/notify-a-web-service-sending-non-blocking-http-requests/43256/2 "2007-12-24T13:33:10Z")

</div>

> i want to notify a webservice of something, but not wait for the  
> response. whats the best way to do this?

HTTP doesn't let you do this reliably. The best thing to do is change  
the service so that it returns immediately to acknowledge receipt of the  
request. Then just use standard Net::HTTP.

> i could use the timeout library i guess with a timeout of 0 ? which i  
> guess spawns a thread...

Or just spawn a thread and then have the thread wait for the response.  
Be careful, however; Ruby threads are not asynchronous when you're  
waiting for IO, unless you're careful to wait in select().

> or use  
> &nbsp;&nbsp;system("curl #{url}")

That will wait for the response.

> is there a UDP package for ruby?

Yes, but you can't do HTTP over UDP; you're misunderstanding the protocol.

cjs

> **···**
>
> On 2007-12-24 21:47 +0900 (Mon), d c wrote:  
> --  
> Curt Sampson \<cjs@starling-software.com\> +81 90 7737 2974  
> Mobile sites and software consulting: [http://www.starling-software.com](http://www.starling-software.com)

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [24 December 2007 17:20 UTC](https://rubytalk.org/t/notify-a-web-service-sending-non-blocking-http-requests/43256/3 "2007-12-24T17:20:21Z")

</div>

If you're able to use the Ruby/EventMachine library, it solves this problem  
easily. Whether you can use it depends on the structure of your program.

The HTTP client inside of EM returns a "Deferrable" object, which  
synchronously notifies your program when the HTTP request completes.

> **···**
>
> On Dec 24, 2007 7:47 AM, d c \<lister@pikkle.com\> wrote:
> 
> > hi -
> > 
> > i want to notify a webservice of something, but not wait for the  
> > response. whats the best way to do this?
> > 
> > is there a way to use a GET call to just send a request and then continue?
