Git Product home page Git Product logo

sprocket's People

Contributors

ekmartin avatar rachelrotteveel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

alxbnct

sprocket's Issues

Add generic file server handler

Should create a handler that can be attached to a base path which would serve files from there.
Could look something like:
(add-handler 'GET "/static" (static-handler "directory")) which would then result in requests such as /static/file.txt returning file.txt from directory.

Remove random prints

There's some random displays and similar laying around for debugging, should remove them before handing in (e.g. in httpio.scm).

JSON middleware

After we have support for generic middleware we should create a JSON body parser and response serializer. The former would take in a request with a JSON body and parse it to a Scheme data structure, while the latter would take a Scheme data structure and serialize it to a JSON string before it's sent back to the user.

https://github.com/joeltg/json.scm

Simpler request handlers

Also inspired by https://github.com/dmac/spin, for request handlers that return 200 with no new headers and just a response, we could turn this:

(define (handler req)
  '(200 () "Hello World!"))

into just

(define (handler req) "Hello World!")

Form parsing middleware

Similar to #4, we could create a generic middleware that would parse HTTP form requests into a data structure. There might be a parser for this in mod-ssp already.

Pass a response object to handlers

Similar to #7, it would probably be useful for middleware and handlers to "tack on" e.g. headers to the response object, so that the final response is a cooperation between all the handlers - instead of just the result of calling one of them. This is also how most web servers work, like Express.

add-handler sugar

Instead of making the developer create handlers by doing (add-handler "POST" "/path" (lambda ())) we could for example define helper methods like (post "/path" (lambda()).

Inspired by https://github.com/dmac/spin

Add logging

All of the useful procedures should log what they're doing when logging is enabled (see #9 for how logging could be enabled).

Add Content-Type header when serving static files

Could set the Content-Type header to the MIME type when serving static files, e.g. image/png for .png files and so on.

Browsers are pretty good at guessing the type, so not horrible if we don't, but there's probably some mime stuff lying around somewhere in scheme if we want to.

Add tests

There's probably some mit-scheme test framework we could use for this.

More sophisticated path matching

The current solution just matches the URL one to one. We should add support for features such as matching variables, i.e. /houses/:houseNumber. Most web servers do this by letting developers define a URL string, and then parse that, but we don't necessarily have to do that. Could do something more schemey with pattern matching etc.

Parse cookies

This relies on #7 really, but we could let the handlers access the user's cookies as a Scheme data structure (e.g. an alist). There's some cookie parsing procedures in src/ssp/mod-lisp.scm in Scheme we can borrow.

Template rendering

This is definitely a stretch goal, but if we have time we could allow request handlers to return HTML with a templating data structure similar to the nested lists e.g. Racket uses:

(send/suspend
 (lambda (k-url)
   (response/xexpr
    `(html (head (title "Enter a number"))
           (body
            (form ([action ,k-url])
                  "Enter a number: "
                  (input ([name "number"]))
                  (input ([type "submit"]))))))))

Add serve-file helper

Similar to the redirect procedure this should call read-file on the given path and return `(200 () ,content) where content is the result of read-file.

Add support for request middleware

Right now the handlers are always terminal, i.e. they have to return a response.
We should add support for handlers that appear in the middle of the request chain, i.e. middleware. One way to do this would be to define handlers that don't return anything as middleware, and then continue until one of them actually do return something.

Add support for error middleware

Should probably be bound to the request handling with bind-condition-handler. There should be a default handler that returns a 500 response if the server goes bananas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.