A simple RESTful web app for logging drinks I like. Uses Mojolicious::Lite & Backbone.js.
JavaScript Perl Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
docs
install
lib
public
screenshots
t
.gitignore
README

README

===== ABOUT =====

A simple, single-page web application that allows you to create, read, update and delete drinks that you like. Uses Mojolicious::Lite to create a RESTful interface, and Backbone.js to manage the communication between the server and the client.

===== INSTALL =====

Required:

  * MySQL (5.1.62 or greater)
  * Perl (5.10.1 or greater) and the following modules:
    - DBI and DBD::mysql
  * Mojolicious

Optional:

  * Test::More
  * FindBin

1. From your terminal, navigate into the root directory for this project:

  $ cd ~/Sources/drinks-i-like

2. Using the MySQL client, create the database `drinks_i_like`, as well as a user with the same name (take note of the password you use):

  mysql> CREATE DATABASE `drinks_i_like`;
  Query OK, 1 row affected (0.07 sec)


  mysql> GRANT ALL PRIVILEGES ON `drinks_i_like`.* TO drinks_i_like@localhost IDENTIFIED BY 'mysecretpassword';
  Query OK, 0 rows affected (0.15 sec)

  mysql>

Note the password you use for this new user; you'll set it in step #5.

3. From the MySQL client, run the SQL script, install/init.sql, to generate the table(s) and sample data.

  mysql> \. install/init.sql
  Database changed
  Query OK, 0 rows affected (0.00 sec)

  Query OK, 0 rows affected (0.09 sec)

  Query OK, 1 row affected (0.01 sec)

  mysql> 

4. Create a configuration file using the sample, and set the password you used:

  $ cp lib/MyConfig.pm.example lib/MyConfig.pm
  
5. Open this configuration file (lib/MyConfig.pm) and set the password:

  package Config;

  sub db_name     { 'drinks_i_like' }
  sub db_username { 'drinks_i_like' }
  sub db_password { 'mysecretpassword' } # <-- HERE

  1;

===== RUN =====

1. Run bin/server:

  $ bin/server 
  [Wed May 16 10:18:52 2012] [info] Server listening (http://*:3000)
  Server available at http://127.0.0.1:3000.

You can modify the PORT variable in this script to select a different port.

2. In your browser, visit: http://127.0.0.1:3000

===== RESTFUL INTERFACE =====

For each of the following, if you visit the site's home page (http://127.0.0.1/ by default), you can run the specified jQuery command from the JavaScript console in your browser to test the functionality.

For more information on building a RESTful interface, see: [http://goo.gl/YjyDM]

1. (Create) To add a drink: POST /api/drink/

    jQuery.post("/api/drink", {
      "title": "Espresso",
      "description": '"It is inhumane, in my opinion, to force people who have a genuine medical need for coffee to wait in line behind people who apparently view it as some kind of recreational activity." - Dave Barry',
    }, function (data, textStatus, jqXHR) {
        console.log("Response: "); 
        console.dir(data); 
        console.log(textStatus); 
        console.dir(jqXHR);
    });

2. (Read)   To get a drink: GET /api/drink/:id

    jQuery.get("/api/drink/1", function(data, textStatus, jqXHR) {
            console.log("Response: ");
      console.dir(data);
      console.log(textStatus);
      console.dir(jqXHR);
    });

  Or to get all drinks: GET /api/drink/

    jQuery.get("/api/drink/", function (data, textStatus, jqXHR) {
            console.log("Response: ");
        console.dir(data);
        console.log(textStatus);
        console.dir(jqXHR);
    });

3. (Update) To update a drink: PUT /api/drink/:id

    jQuery.ajax({
        url: "/api/drink/1",
        type: "PUT",
        data: {
          "description": '"Baby mammals drink milk, and you sir, are a baby mammal." - Mark Rippetoe'
        },
        success: function (data, textStatus, jqXHR) {
            console.log("Response: ");
            console.dir(data);
            console.log(textStatus);
            console.dir(jqXHR);
        }
    });

4. (Delete) To delete a drink: DELETE /api/drink/:id

    jQuery.ajax({
        url: "/api/products/1", 
        type: "DELETE",
        success: function (data, textStatus, jqXHR) {
            console.log("Response: ");
            console.dir(data); 
            console.log(textStatus); 
            console.dir(jqXHR); 
        }
    });

===== USEFUL RESOURCES =====

* Develop a RESTful API Using Node.js With Express and Mongoose [http://goo.gl/G1u4j]

* Designing a RESTful Web Application [http://goo.gl/YjyDM]