REST WS with Python + hosting on a shared server

Apr 18

I encountered a situation where I needed a simple REST WS to be hosted on my shared server. unfortunately Java wasn’t an option as most shared hosting providers don’t support Java. I decided to go with Python as it’s already supported however that was not an easy ride.

  1. Prerequisites
  2. Before wasting a lot of time we need to make sure the following items are available:

    1. You can SSH your shared server
    2. Some hosting providers don’t enable this feature by default however you will be able to enable it by dropping them a mail.

    3. Python is installed on the server
    4. Simply run the following command on your server:

      For me the installed version was 2.6. If you have another version the syntax below may differ a little bit specially if you have version 3.

    5. You can edit your .htaccess file
    6. The original steps included modifications on httpd config file however I didn’t have access on that file. I didn’t see any provider who’s preventing the edits of .htaccess however it worth checking as we will add a new Apache Handler

  3. Creating REST WS using Python
  4. Now let’s create our REST WS. There are many frameworks that could be used while creating a REST WS in Python. For example Django, CherryPy,, Flask and Bottle will do the job. For my experiment I went with

    Now connect to your server using SSH and perform the following:

    1. Create a folder on the server
    2. Download the needed libraries and extract them
    3. Create the REST WS file
    4. Create a new file named inside sandbox folder and add the following code to it.

  5. Configuring your shared server
  6. Add the following content at the end of your .htaccess file.

  • Test your REST
  • Now you should be able to run some testing requests using the browser or any plugin such as Firefox RESTClient. The URL will be http://yourdomain/path/to/sandbox/

    The above will print “message Hello, world!”. You can also send a parameter after the URL to print it.

    Finally, there are another ways to achieve the above however this was the easiest for my. Below is a list of useful resources if you need to check other ways.

    Leave a Reply