chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] dynamic web resources?


From: Mario Domenech Goulart
Subject: Re: [Chicken-users] dynamic web resources?
Date: 16 Oct 2006 10:02:32 -0300
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hello,

On Sun, 15 Oct 2006 06:45:35 -0700 Kon Lovett <address@hidden> wrote:

> On Oct 15, 2006, at 5:04 AM, Andreas Zwinkau wrote:
> 
> > Hi,
> >
> > i want to make a "RESTful" webapp and i need dynamic urls for this.
> > Neither "http" nor "spiffy" offer this. I thought about extending
> > "http" for something like:
> >
> >     (http:add-dynamic-ressource "/entries/{id}" my-handler)
> >
> > I'd prefer to build it (with a nicer interface for the handlers) on
> > top of something, which handles the http connection stuff for me,
> > but this doesn't seem possible?
> >
> > Since i'm new to Chicken, i'm not sure how to do this.
> 
> This might help:
> 
> http://lists.gnu.org/archive/html/chicken-hackers/2006-10/msg00007.html

As Kon pointed, I've been working on a URL dispatcher for the
Chicken http server which may be something similar to what you want.

In the file attached to the message pointed by the link above, you can
find the code to map a part of an URL to a Scheme procedure name.  To
achieve that, the http-server's `http:find-resource' procedure needs
to be modified to match regexes.  As far as I understand, it's similar
to what you suggest as `http:add-dynamic-resource'.

Currently I've added support to use values of GET and POST variables
(as well as paths) as arguments to Scheme procedures (this feature is
not implemented in the file attached to the message sent to
chicken-hackers).

An example:

,----[ web-server.scm ]
| (use spiffy web-scheme url-dispatcher)
| 
| (register-dispatcher "/names")
| 
| (define-callable-url (show-some-name #!optional name)
|   (html
|    (body
|     (p "Name is " (or name "no name"))
|     (make-form 'show-some-name
|                (p "Name: " (input 'type "text" 'name "name")
|                   (input 'type "submit"))))))
| 
| (start-server port: 8080 root: "." debug: #t)
`----

In the code above, I've defined a `show-some-name' procedure which can
be invoked by accessing http://localhost:8080/names/show-some-name.
If no argument is used, it will print "Name is no name" and a form
prompting for a name.  If the form is filled and the submit button is
pressed, the text box value is used as argument to `show-some-name'
and "Name is <whatever was filled>" will be printed.

The `make-form' procedure uses as its first argument the name of a
handler which should be previously defined with `define-callable-url'.
The default method used by `make-form' is POST.  The handler is
invoked when the form data is submited.

Accessing

  http://localhost:8080/names/show-some-name?name=mario

or

  http://localhost:8080/names/show-some-name/mario

would both pass `mario' as argument to `show-some-name'.

As mentioned in the message pointed by Kon, these things only work if
the Chicken http-server has its http:find-resource' procedure
modified accordingly.

Best wishes,
Mario




reply via email to

[Prev in Thread] Current Thread [Next in Thread]