On Thursday, June 1, 2017 at 10:43:13 PM UTC+2, Jay McCarthy wrote:
> I believe that you want `dispatch-rules!` rather than `dispatch-rules`
> 
> http://docs.racket-lang.org/web-server/dispatch.html?q=dispatch-rules#%28part._.Imperative_.Dispatch_.Containers%29
> 
> This lets you define a container of routes that is used by your
> top-level and then various parts of your application inject their
> URL<->fun mappings into it.
> 
> Jay
> 
> On Tue, May 30, 2017 at 6:47 PM, Zelphir Kaltstahl
> <zelphirkaltst...@gmail.com> wrote:
> > I have the following server specification:
> >
> > (define (start request)
> >   ;; for now only calling the dispatch
> >   ;; we could put some action here, which shall happen before each 
> > dispatching
> >   (hsk-dispatch request))
> >
> > (define-values (hsk-dispatch a-url)
> >   (dispatch-rules [("") #:method "get" overview-app]
> >                   [("index") #:method "get" overview-app]
> >                   [("home") #:method "get" overview-app]
> >                   [("hsk") #:method "get" hsk-app]
> >                   [("ajax" "hsk-1-data") #:method "get" hsk-1-data]))
> >
> > (serve/servlet
> >   start
> >   #:servlet-path "/index"  ; default URL
> >   #:extra-files-paths (list (build-path (current-directory) "static"))  ; 
> > directory for static files
> >   #:port 8000 ; the port on which the servlet is running
> >   #:servlet-regexp #rx""
> >   #:launch-browser? false  ; should racket show the servlet running in a 
> > browser upon startup?
> >   ;; #:quit? false  ; ???
> >   #:listen-ip false  ; the server will listen on ALL available IP 
> > addresses, not only on one specified
> >   #:server-root-path (current-directory)
> >   #:file-not-found-responder respond-unknown-file)
> >
> > With some requires of other modules etc.. I am adding routes in the 
> > dispatch-rules part of the program. However, I'd like to add routes and 
> > specify which procedures handle requests to them elsewhere in the program.
> >
> > The reason why I want to do this is, that I want to create a procedure 
> > similar to what I recently saw in Chicken Scheme's web framework Awful:
> >
> > http://wiki.call-cc.org/eggref/4/awful#using-ajax
> >
> > There is a procedure, which generates jQuery code, which is on a web page, 
> > which then requests a route, which I can specify when I call the ajax 
> > procedure.
> >
> > I wonder if (1) and how (2) I could specify routes like that outside of the 
> > dispatch-rules part of the program, so that I could get something like 
> > Awful's ajax procedure (3) or maybe if there even already is such a thing 
> > for Racket's webserver (4).
> >
> > What I like about it is, that I can code everything "on the server side" 
> > and in Racket instead of having to switch to JavaScript at some point and 
> > still I am able to "connect" parts of the actual DOM elements to procedures 
> > on the server side. Without such a thing, it might be better to let the 
> > server send only raw data and handle all DOM tree logic in JavaScript in a 
> > static JavaScript file, because that way, I'd have knowledge about the DOM 
> > elements in the code, because I'd be creating them in JavaScript on the 
> > basis of that raw knowledge. On the other hand, if I render some HTML on 
> > the server side and send it to the client and the client needs to modify it 
> > and inform the server about it, I'll have to rely on certain ids and 
> > classes of DOM elements simply being there, while I had to switch context 
> > to JavaScript. This feels less clean than either generating all DOM 
> > elements in JavaScript code or generating everything with a procedure like 
> > Awful's ajax procedure.
> >
> > I don't need much, probably only a few click listeners, so maybe my 
> > procedure could be less complex than the ajax of Awful. Or since Racket is 
> > very similar in Syntax, I could try to copy most of the code.
> >
> > For another utf8 related reason, I cannot use Chicken Scheme at the moment, 
> > so I reimplemented everything in Racket, where I do not have that problem, 
> > but also do not know of any such ajax procedure.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> -=[     Jay McCarthy               http://jeapostrophe.github.io    ]=-
> -=[ Associate Professor        PLT @ CS @ UMass Lowell     ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-

This does seem like what I want. Thank you!
Can you point me to any part of the documentation, which explains what the 
parameters to dispatch-rules! are? They are named differently than the ones to 
dispatch-rules, I guess for a reason, but I cannot find anything about what 
they are.
Do I have to define-container? I did not do that for dispatch-rules.
An example of how to use the procedure dispatch-rules! would be useful. Can you 
point me to one such?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to