Live data from Hacker News

Low-level web programming in Racket and a wiki in 500 lines

matt.might.net

21–29 of 29 posts

Re: Low-level web programming in Racket and a wiki in 500 lines

#22
post #14

Very nice proof of concept. Just a word of warning: In practice you want to sanitize your input. The code in "Serving static files" allows to break out of document-root with "..".

Have you tried to actually exploit that? I don't currently use Racket myself, but I would expect request-uri to prevent ".." and if it didn't surely url-path would.

  ; extract the URI from the request:
  (define uri (request-uri req))
  
  ; extract the resource from the URI:
  (define resource 
    (map path/param-path (url-path uri)))
  
  ; find the file location:
  (define file (string-append
                document-root
                "/" 
                (string-join resource "/")))

Re: Low-level web programming in Racket and a wiki in 500 lines

#23
post #3

I'm glad to see someone talking about using the lower-level web libraries in Racket. The high-level continuation-based ones are ridiculously unsuitable for actual web programming (they store full state on the server at all times, and the URL gives you full access to the session, among other issues), but the lower-level ones actually look pretty clean and modern. And yet all the documentation keeps talking about the c…

The issues you mention are all alleviated by the stateless continuations which do not store state on the server and allow various ways of closing off the session from simply having the URL.

The documentation discusses the features of the Web framework, many of which have to do with its unique aspects. As you can see in this post, all normal Web programming is possible and easy, but there's very little special to say about it, because it's just a normal program.

Re: Low-level web programming in Racket and a wiki in 500 lines

#24

Earlier quoted context omitted.

How exactly are you hung up with form data? Its low level, so you certainly can't get validation out of box, but otherwise in my experience getting form data out is fairly straight forward. I recently wrote my first Racket web app. Its not pretty or following best practices but you can take a look. https://github.com/vishesh/whalebin

Thank you! Your project was helpful to skim through. Do you have any additions to the web-project-bootstrap.rkt project? BTW, this is what I mean by form bindings being confusing: according to the docs, request-bindings is dangerous and shouldn't be used http://docs.racket-lang.org/web-server/http.html#%28mod-path... . That's kind of confusing, because request-bindings is used in the tutorial docs: http://docs.racket…

The request-post-data/raw function is in the docs: http://docs.racket-lang.org/web-server/http.html?q=post-data...

Re: Low-level web programming in Racket and a wiki in 500 lines

#26

Earlier quoted context omitted.

How exactly are you hung up with form data? Its low level, so you certainly can't get validation out of box, but otherwise in my experience getting form data out is fairly straight forward. I recently wrote my first Racket web app. Its not pretty or following best practices but you can take a look. https://github.com/vishesh/whalebin

Thank you! Your project was helpful to skim through. Do you have any additions to the web-project-bootstrap.rkt project? BTW, this is what I mean by form bindings being confusing: according to the docs, request-bindings is dangerous and shouldn't be used http://docs.racket-lang.org/web-server/http.html#%28mod-path... . That's kind of confusing, because request-bindings is used in the tutorial docs: http://docs.racket…

request is a struct with the field post-data/raw, so this implies that request-post-data/raw can access the field.

http://docs.racket-lang.org/web-server/http.html?q=request#%...

Re: Low-level web programming in Racket and a wiki in 500 lines

#27
post #16

Isn't your `any?` function actually `ormap`[0]? You should be able to do the same thing with: (ormap password-matches? line) 0 - http://docs.racket-lang.org/reference/pairs.html?q=ormap#%28...

Yep! Jay McCarthy pointed this out, and I changed it. :)

Re: Low-level web programming in Racket and a wiki in 500 lines

#28
post #3

I'm glad to see someone talking about using the lower-level web libraries in Racket. The high-level continuation-based ones are ridiculously unsuitable for actual web programming (they store full state on the server at all times, and the URL gives you full access to the session, among other issues), but the lower-level ones actually look pretty clean and modern. And yet all the documentation keeps talking about the c…

The continuation-based libraries are the simplest, easiest, quickest way to get a program off the ground. They make interactive Web programming just as easy as writing “scanf” or its equivalent, _and_ are safe in the face of various browser interactions. Therefore, they're a good default for prototyping. However, I agree that they also have issues, and the documentation should not over-emphasize them, but rather indi…

I think that depends on where you're coming from. If you're a longtime web developer, stateless request/response are in your blood, and stateful, persistent programming is deeply weird.

Re: Low-level web programming in Racket and a wiki in 500 lines

#29
post #3

I'm glad to see someone talking about using the lower-level web libraries in Racket. The high-level continuation-based ones are ridiculously unsuitable for actual web programming (they store full state on the server at all times, and the URL gives you full access to the session, among other issues), but the lower-level ones actually look pretty clean and modern. And yet all the documentation keeps talking about the c…

The issues you mention are all alleviated by the stateless continuations which do not store state on the server and allow various ways of closing off the session from simply having the URL. The documentation discusses the features of the Web framework, many of which have to do with its unique aspects. As you can see in this post, all normal Web programming is possible and easy, but there's very little special to say…

"It's just normal" is a thing that I think is good to communicate. Being able to use Racket to write web apps in ways that wouldn't be unfamiliar to Node devs makes the Lispy thing seem less weird and intimidating.
Post reply on HN