Shared publicly  - 
 
Without resorting to Java, what the easiest way to write a small REST server? I basically want to upload a few files over HTTP without any kind of encryption or login names to a public server and then present the user a link they can download that single file from. Ideas?
1
Philip Withnall's profile photoRalph Corderoy's profile photoRichard Hughes's profile photoRobin Norwood's profile photo
23 comments
 
Mmm.. probably can write this in 20 minutes or so using http://screencasts.org/episodes/ajax-website-with-sinatra-jquery as a bootstrap and then adding the file uploader as a form. There is another screencast on the same site that's just Sinatra, so maybe 30 minutes total. If you need a multithreaded server, you could run Nginx in the same development cycle in a few more minutes.
 
I'd use jboss resteasy. But that would be resorting to java... But it's super easy. if you can type @GET, @POST, etc you can use resteasy.

You could use PHP and switch off of the $_SERVER['request_method']. But I think it's less straight forward than RESTeasy.
 
Oh, I think I misunderstood: if you want to make an actual webapp, not just an API, you'd probably be better off with something like Sinatra (Ruby) or Flask (Python).
 
Personally, I'd use Flask or Bottle, both python "microframeworks". Ruby or even PHP would work; between the three, the decision depends more on the preference of the implementor than anything else.
 
Is this for ColorHug? If you decide to go the Python route, and want some help, let me know. I'll be happy to help, time permitting.
 
Using Scala, you could use (in rough order of bareboneness to featurefulness):

- Unfiltered (http://unfiltered.databinder.net/Unfiltered.html)
- Scalatra (https://github.com/scalatra/scalatra)
- Xitrum (https://github.com/ngocdaothanh/xitrum)
- Pinky (https://github.com/pk11/pinky/wiki/)
- Play 2.0 (http://www.playframework.org/)

Using Play, the way to do it would be to write an upload handler (see http://www.playframework.org/documentation/2.0/ScalaFileUpload) then write a simple controller that allows access to the files that have been uploaded, similar to the one that serves static assets (https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/controllers/Assets.scala). The Asset controller is rather complex due to handling caching and etags (neither of which you really need for a download-only website), and the code for your controller is probably going to be something similar to:

def serveFile() = Action { request => Ok.sendFile(new File(request.path)) }

Obviously, add some checks so that someone can't download /etc/passwd and overwrite random files on the system.
 
IMO for this task the easiest way is what language do you know, Apache even has a mod_upload (http://commons.apache.org/fileupload/) tho I like nginx more depending on the case, I love perl so doing this in perl would take little time for me, if you are better at python/ruby/php... this is an easy task that any alternative will do the job.
 
Hmm, I had a play last night and my Vidahost shared server doesn't seem to have all the bits needed for a Python framework. I've got no root access on the box. :(
 
what about using python/ruby on some PaaS openshift/heroku?
 
+Philip Withnall Sure, it's got python but not Flash or Bottle, or any of the deps they need. Yell if I'm being a moron.
 
I don’t know if the same is true for Flash or Bottle, but I know that Django can be run without being installed system-wide. I’d sort of assumed the same was true of other Python frameworks, but I could be being the moron here.
 
+Richard Hughes, one of Bottle's claims to fame is that it's a single file and can by placed alongside your own code. Something similar may be true of others, e.g. Flask. No matter that your provider doesn't provide.
 
+Richard Hughes You "should" be able to install a local (ie, in your home directory) python module like bottle or flask; depending on your python version and your hosting provider's setup, the "how" varies. easy_install and pip are the two more common methods. If they're set up "right", it might be as easy as "easy_install bottle" or "pip install bottle".
Add a comment...