joaotavora / snooze

Common Lisp RESTful web development
207 stars 22 forks source link

how to send a file #38

Closed badbettty closed 4 months ago

badbettty commented 4 months ago

there should be an apology for this (especially as no code etc attempt is made) ... but hey ho

please provide an example (description or code) of the best way to serve a file (from file system) using snooze when working with hunchentoot ?

hunchentoot has a file serving handler, but how does one hook into this after snooze has dealt with the restful request uri ... or is it a case of writing code within the snooze method to serve file to a response stream (but which stream/where etc) ?

cheers for any ideas

mdbergmann commented 4 months ago

I set it up in front of the hunchentoot *dispatch-table* like so:

    (push (make-routes) ;; snooze routes
          hunchentoot:*dispatch-table*)
    (push (hunchentoot:create-folder-dispatcher-and-handler "/static/" *static-directory*)
          hunchentoot:*dispatch-table*)
badbettty commented 4 months ago

well - it seems hunchentoot's 'handle-static-file' can do the job if called within a defroute:

eg: (snooze:defroute testroute (:get :application/pdf docref) (hunchentoot:handle-static-file #p"/somefolder/somesubfolder/somefile.xml" )) I'll live with this, if no one knows of a reason why not to :-)

badbettty commented 4 months ago

I set it up in front of the hunchentoot *dispatch-table* like so:

    (push (make-routes) ;; snooze routes
          hunchentoot:*dispatch-table*)
    (push (hunchentoot:create-folder-dispatcher-and-handler "/static/" *static-directory*)
          hunchentoot:*dispatch-table*)

hello there - are you creating snooze routes (defroute) and pushing them into dispatch-table ?

Can you provide a brief example of your 'make routes' code please ?

mdbergmann commented 4 months ago

Well, (make-routes) basically just wraps (make-hunchentoot-app) but in another package that imports :snooze and has the defroute definitions.

badbettty commented 4 months ago

ok got it ... cheers :-)