J1RestSampleDemo

Revision as of 18:33, 6 November 2009 by Admin (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

Music App using REST API

Overview

This document outlines a JavaOne demo scenario. The intent of this demo scenario is to showcase REST CRUD (Create, Retrieve, Update, Delete) functionality with a cool application. The audience of this needs to have only basic HTTP knowledge.

We would showcase a Music App, that provides the following functionality

  • Users would be able to signup and login to the app.
  • Users would be able to create playlist.
  • A playlist would have a title and description
  • A playlist contain collection of songs, and each song metadata would contain
  • title, artist name and address (optional), url of the song, source of the song (may be a site url)
  • Users could search songs from playlist of thier own or other users, and play music from this app.
  • Maintainence:
  • Playlist can be edited, deleted
  • Songs from playlist could be edited and deleted as well.

Scenario

In a typical scenario.

  • A user creates playlists. Each playlist could contain 0 or more songs. Each song belongs to an artist

who creates them.

  • Another user of the application logs in, then searches for playlists. If found this user views the playlist, and plays selected songs from the playlists.

Below is an illustration of how a user creates a playlist.

Step1: A user logs into the application, views playlists of all users in this application, as shown below.

In this step following REST functions are invoked

METHOD URL PROTOCOL Comments
GET /music/users/{id}/playlists HTTP/1.1


home page of music app

Step 2: The user then clicks link 'Nova' inside the view playlist table. This takes the user to the playlist 'Nova' page as shown below.

In this step following REST functions are invoked

METHOD URL PROTOCOL Comments
GET /music/playlists/{id} HTTP/1.1
GET /music/playlists/{id}/songs HTTP/1.1


nova playlist

Step 3: Next the user can listen to this song by following URL 'link', or check the 'site' from where this song belongs, or click the 'Map It' link on the artist address if any. The 'Map It' link shows the google map of the artist in a seperate browser window.

Mext the user clicks link 'Add Song' to futher add a song to this playlist called 'Nova', as shown below. After click 'Submit' the user is taken back to the playlist for 'Nova'. A delete link for each song is provided to delete it from the playlist.

In this step following REST functions are invoked

METHOD URL PROTOCOL Comments
POST /music/users/{id}/playlists/songs/{id} HTTP/1.1
DELETE /music/users/{id}/playlists/songs/{id} HTTP/1.1 Not shown in the screenshot


add a song to nova playlist

Showing Google map for the artist address: add a song to nova playlist

Step 4: In this step user clicks menu item 'Create Playlist', where the user can create a new playlist. See below.

In this step following REST functions are invoked

METHOD URL PROTOCOL Comments
POST /music/users/{id}/playlists/{id} HTTP/1.1
DELETE /music/users/{id}/playlists/{id} HTTP/1.1 Not shown in the screenshot


create playlist

REST uri

METHODS URL PROTOCOL
GET, POST /music/users HTTP/1.1
GET, PUT, DELETE /music/users/{id} HTTP/1.1
GET, POST /music/playlists HTTP/1.1
GET, PUT, DELETE /music/playlists/{id} HTTP/1.1
GET, POST /music/users/{id}/playlists HTTP/1.1
GET, POST /music/playlists/{id}/songs HTTP/1.1
GET, PUT, DELETE /music/playlists/{id}/songs/{id}/artists/{id} HTTP/1.1
GET, PUT, DELETE /music/playlists/{id}/songs/{id}/artists/{id}/address HTTP/1.1


Legend

Following patterns are suppored in current REST implementation

  • Container - GET, POST
  • Containee(Entity) - GET, PUT, DELETE

DB Schema

Music DB Schema

Resources

  • Download Music Demo App from here here . After unzip, making necessary selection of app server (the app

was configured for tomcat 5.5), deploy and run the app pointing to url

http://localhost:8080/MusicDemo/index.jsp

  • To invoke testclient, run 'Testing Resource Beans" from the project node 'MusicDemo'.
  • Another article developing web app using REST

http://idealliance.org/proceedings/xtech05/papers/02-07-04/

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo