# Looking for Webric example code

**URL:** <https://www.ruby-forum.com/t/looking-for-webric-example-code/69747>\
**Category:** Ruby\
**Created:** [September 23, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747 "2006-09-23T19:50:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 23, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/1 "2006-09-23T19:50:36Z")

</div>

I need examples of writing Webric code handling GET and POST requests.  
Thanks!  
Dima

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 23, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/2 "2006-09-23T23:12:03Z")

</div>

On Sep 23, 2006, at 12:50 PM, Dmitri K. wrote:

> I need examples of writing Webric code handling GET and POST requests.  
> Thanks!

Google is your friend:

[http://www.google.com/search?q=webrick](http://www.google.com/search?q=webrick)

See the Hello Servlet example on the first link, or follow the links  
on that page to:

[http://microjet.ath.cx/webrickguide/html/do\_Methods.html](http://microjet.ath.cx/webrickguide/html/do_Methods.html)

and:

[http://segment7.net/projects/ruby/WEBrick/servlets.html](http://segment7.net/projects/ruby/WEBrick/servlets.html)

James Edward G. II

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 24, 2006, 12:06am UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/3 "2006-09-24T00:06:29Z")

</div>

Thanks a lot James! This is exactly what I was looking for! (or maybe I  
should go to ROR directly, without stoping at WEBrick?..)

James G. wrote:

> On Sep 23, 2006, at 12:50 PM, Dmitri K. wrote:
> 
> > I need examples of writing Webric code handling GET and POST requests.  
> > Thanks!
> 
> Google is your friend:
> 
> [webrick - Google Search](http://www.google.com/search?q=webrick)
> 
> See the Hello Servlet example on the first link, or follow the links  
> on that page to:
> 
> [http://microjet.ath.cx/webrickguide/html/do\_Methods.html](http://microjet.ath.cx/webrickguide/html/do_Methods.html)
> 
> and:
> 
> [http://segment7.net/projects/ruby/WEBrick/servlets.html](http://segment7.net/projects/ruby/WEBrick/servlets.html)
> 
> James Edward G. II

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 24, 2006, 12:48am UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/4 "2006-09-24T00:48:16Z")

</div>

I’ve had to “upgrade” to 1.8.5, and suddenly PTY is doing weird stuff.  
After it looses a connecting, even though I have it in a  
begin  
rescue  
end

sort of structure, it throws an exception and crashes after it exits the  
def, throwing an exception

pty - exited: 26825 (PTY::ChildExited)

and bombs, unless i put a rescue structure around the next IO type  
operation… I don’t understand, this didn’t happen in 1.8.1

Please help!

Mark

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 24, 2006, 2:54am UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/5 "2006-09-24T02:54:57Z")

</div>

“or maybe I should go to ROR directly, without stoping at WEBrick?”

Depends on what you need. I use Webrick a lot to (among  
other things) specify different document roots dynamically, ie  
when someone needs a certain file which he cant find on the www but  
which is in one of my archives, then a ruby scripts dumps that  
file into a temporary dir and starts a special webrick server  
for a limited amount of time before cleaning up again.

There are myriads of more different usage examples, my bottom  
line would be that it never hurts to have a good look at Webrick  
for the stuff YOU could need 🙂

Btw about the Google thing - I feel that Webrick is underrepresented  
on Google as far as up-to-date examples are considered. So google  
is NOT always the best solution, i have had recieved more help when  
posting specific questions about Webrick in the past too.

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 24, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/6 "2006-09-24T23:26:41Z")

</div>

On 23 Sep 2006, at 23:06, Dmitri K. wrote:

> Thanks a lot James! This is exactly what I was looking for! (or  
> maybe I  
> should go to ROR directly, without stoping at WEBrick?..)

WEBrick is very good for writing quick and dirty HTTP servers -  
especially if all you want to do is mount some code at a given URL  
and return some output nicely wrapped with HTTP headers etc. Writing  
complex web applications with vanilla WEBrick is a little more  
challenging but can be done however you’re probably better off using  
RoR, Camping or one of the other frameworks.

Ellie

## Eleanor McHugh Games With Brains

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 24, 2006, 11:57pm UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/7 "2006-09-24T23:57:26Z")

</div>

Eleanor McHugh wrote:

> On 23 Sep 2006, at 23:06, Dmitri K. wrote:
> 
> > Thanks a lot James! This is exactly what I was looking for! (or  
> > maybe I  
> > should go to ROR directly, without stoping at WEBrick?..)
> 
> WEBrick is very good for writing quick and dirty HTTP servers -  
> especially if all you want to do is mount some code at a given URL  
> and return some output nicely wrapped with HTTP headers etc. Writing  
> complex web applications with vanilla WEBrick is a little more  
> challenging but can be done however you’re probably better off using  
> RoR, Camping or one of the other frameworks.
> 
> Ellie
> 
> ## Eleanor McHugh Games With Brains
> 
> raise ArgumentError unless @reality.responds\_to? :reason

Thanks for update! I am thinking about using Webric for lightweight  
REST-full protocol between WEB peers. In other words I need embedable  
WEB server that will allow sevral apps exchange messages using simple  
protocol on top of HTTP (get & post + params).  
The main question here: can Webric be embeded in another application so  
threads of this app will not be blocked and will continue to work  
without starvation. In fact, application I am talking about may use  
variable number of threads growing from 1 to 100 at different times  
(these in addition to Webric threads).

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 25, 2006, 12:54am UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/8 "2006-09-25T00:54:49Z")

</div>

On 24 Sep 2006, at 22:57, Dmitri K. wrote:

> Thanks for update! I am thinking about using Webric for lightweight  
> REST-full protocol between WEB peers. In other words I need embedable  
> WEB server that will allow sevral apps exchange messages using simple  
> protocol on top of HTTP (get & post + params).

I spent several months earlier in the year working on something very  
similar (all closed-source unfortunately) and WEBrick provided a good  
base.

> The main question here: can Webric be embeded in another  
> application so  
> threads of this app will not be blocked and will continue to work  
> without starvation. In fact, application I am talking about may use  
> variable number of threads growing from 1 to 100 at different times  
> (these in addition to Webric threads).

Well WEBrick uses its own thread pool and seems to do a pretty good  
job of managing it, but they are green threads so you’ll have to make  
sure that none of the threads in your application are blocking or  
else the whole thing will stall. Depending upon your platform and how  
computationally intensive your application threads are you may run  
into some latency problems, but I doubt this will be the case with  
the number of threads in question. If latencies do ocur you might  
like to look at using dRb (distributed Ruby) to run some of your  
computationally intensive tasks in separate processes.

Ellie

## Eleanor McHugh Games With Brains

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![dokondr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dokondr](https://www.ruby-forum.com/u/dokondr)\
**Post date:** [September 25, 2006, 1:54am UTC](https://www.ruby-forum.com/t/looking-for-webric-example-code/69747/9 "2006-09-25T01:54:53Z")

</div>

Dmitri K. wrote:

> Thanks a lot James! This is exactly what I was looking for! (or maybe I  
> should go to ROR directly, without stoping at WEBrick?..)

You should also look at Nitro, IOWA and Cerise. Each these has a  
different approach to Web development, and you might do well to find out  
which one best maps to what you want to do.

You can also use Mongrel or Serverside in place of WEBrick; either of  
those should give you better performance than WEBrick.

–  
James B.

“A language that doesn’t affect the way you think about programming is  
not worth knowing.”

- A. Perlis
