Napster REST API
NapsterWe are a Best Buy company We are the best deal on the internet$5 a month for 5 downloadable MP3s + Unlimited streaming of 10million tracksWe have a brand new sitehttp://music.napster.comWe have a live REST API since Januaryhttp://developer.napster.comWe are actively working on putting the music onPhones, Bluray Players, IPTVs & pretty much all the connected devices We are also working with developers to create music appsone app so far (http://twt.fm)The API team is a small agile team of 6We started the project in July and released the first version for the CES at January
AgendaWhat’s REST?Quick tutorial on RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
AgendaWhat’s REST?Quick tutorial on RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
REST  Representational State Transfer www.library.comUser requests a Resource using URLhttp://www.library.com/books/books          /175 – Effective Java 2nd – Josh Bloch         /952 – Windows MFC – Jeff Prosise         /319 – C++ Programming – Bjarne Stroustrup         /367 – UML Distilled – Martin Fowler         /361 – Beginning Oracle – Tom Kyte         /245 – Doman Driven Design – Eric Evans         /298 – Lucene in Action – Erik Hatcher         /395 – Ext GWT RIA – Grant Slender         /392 – Tomcat 6 – Vivek Chopra         /281 – RESTful Services – Sam RubyA Representation of the Resource is returned, and thus placing the client application in a State. The Representation contains hyperlinks to other related Resources (individual books).User clicks a hyperlink on the pageA Representation of another Resource is returned, and thus causing a Transfer of client application State This constant Transfer in client’s State through various Representations is “Representational State Transfer”
RESTRoy Fielding introduced REST Architectural Style for distributed hypermedia systems
What is an ‘Architectural Style’?An Architectural style is way of classifying architectures based on a set of “architectural constraints”Gothic Architecture:The ‘Clustered Columns’, ‘Pointed Ribbed Vaults’ and the ‘Flying Buttresses’ makes this a Gothic Architecture
REST Architectural Style ConstraintsClient-Server – clients separated from server by uniform interface
Stateless – no client context stored on server
Cacheable – responses must define themselves as cacheable or not
Layered System – intermediary servers for load balancing, shared caches and enforce security
Code on Demand (optional) – customize client functionality by transferring logic (applets or javascript)
Uniform Interface – (next slide)  Guiding principles of REST InterfaceIdentification of Resources
Individual resources are identified in requests using URIs
Manipulation of Resources
Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE
Self descriptive messages
Each message includes enough information on how to process the message. Responses also indicate their cacheability.
Hypermedia As The Engine Of the Application State   (HATEOAS)
Related resources should be identified in the representation returned by providing their URIsWhat do we gain by going REST?Conforming to the REST architectural style, will enable a distributed hypermedia system to have desirable emergent properties such as performance, scalability, simplicity, modifiability, visibility, portability and reliability.The largest known implementation of a system conforming to the REST architectural style is the WWW
SOAP vs RESTSOAP Coffee RequestPOST /askCoffeePolitelyHTTP/1.1Host: www.coffee.comContent-Type: application/soap+xml; charset=utf-8Content-Length: 100<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.coffee.com/askCoffeePolitely"><m:GetCoffee>    <m:NumberOfCoffees>1</m:NumberOfCoffees>  </m:GetCoffee></soap:Body></soap:Envelope>REST Coffee Request GET /askCoffeePolitely/coffee?numberOfCoffees=1 HTTP/1.1Host: www.coffee.com
SOAP vs REST
Big advantage of RESTYour REST API
AgendaWhat’s REST?Quick tutorial on RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
JAX-RS SpecificationDefines a set of Java APIs for development of Web Services build according to the REST architectural style. Goals:POJO Based - Provides a set of annotations and associated classes/interfaces that can be used with POJOs to expose them as Web Resources. HTTP Centric - Provide clear mappings between HTTP & URI elements and corresponding API classes and annotationsFormat Independent -  Provide necessary pluggability of content typesContainer Independent - Artifacts using the API will be deployable in a variety of web-tier containers
JAX-RS Implementations(as quoted by some one else)there's a strange phenomenon regarding buses: you wait ages for one, then three come along at once! The same seems to be true for JAX-RS implementations. At the moment we have:Restletprobably the first REST framework, which existed prior to JAX-RSCXFwhich is a merger between XFire and Celtix (an Open Source ESB, sponsored by IONA and originally hosted at ObjectWeb) Jerseythe JAX-RS Reference Implementation from SunRESTEasyJBoss's JAX-RS project
AgendaWhat’s REST?Introduction SOAP vs RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
To get started on the APIGenerate an API Key from developer portal http://developer.napster.com
Signin using your napster account (or) Signup for a new account
Generate an API Key from [Keys & Account Info] section
Use this Excel sheet
Napster_API_Test_Console_Excel.xls
and copy/paste your API Key into the apiKey cell
Create a SessionKey
by clicking the CreateSession
and copy/paste your Session Key into sessionKey cell
Now you can access all the REST API Services (Resources) and get their XML/JSON representationREST API ServicesPublic APISearch
Genre
Album
Artist
Track
Radio
Automix
Napster Playlists
Staff Picks
Image
SecurityPrivate APISecurity (login)
User
Track (playTrack)
BillboardFull API documentation is at the Portal  http://developer.napster.com/docs/
AgendaWhat’s REST?Introduction SOAP vs RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
Napster REST API ArchitectureSecurityCachingResponse FormatError HandlingVersioningContinuous Integration
Quick note:We put our Request details in ThreadLocal variables so that we don’t have to pass it around in method parametersSince tomcat reuses threads we clear it before a request is doneSecurityCachingResponse FormatError HandlingVersioningContinuous Integration
Security – API Key / Session KeyAPI Keys are
Generated by Developer Portal per Application
To be kept “SECRET”
To be used through Secure protocol (https://) only
Unchanging, it never Expires
Session Keys are
Generated by the Applications by calling “CreateSession” or “Login” APIs
Validated for all incoming API requests (except CreateSession, Login)
Can be used in an Unsecured protocol (http)
Good for only 6 hours, it ExpiresSecurity ModelDevelopers or Partners can have one of more API Keys, each one mapped to an application
For Selected Developers or Partners their API      Key is given access to One or more Private APIs

LAJUG Napster REST API

  • 1.
  • 2.
    NapsterWe are aBest Buy company We are the best deal on the internet$5 a month for 5 downloadable MP3s + Unlimited streaming of 10million tracksWe have a brand new sitehttp://music.napster.comWe have a live REST API since Januaryhttp://developer.napster.comWe are actively working on putting the music onPhones, Bluray Players, IPTVs & pretty much all the connected devices We are also working with developers to create music appsone app so far (http://twt.fm)The API team is a small agile team of 6We started the project in July and released the first version for the CES at January
  • 3.
    AgendaWhat’s REST?Quick tutorialon RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
  • 4.
    AgendaWhat’s REST?Quick tutorialon RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
  • 5.
    REST RepresentationalState Transfer www.library.comUser requests a Resource using URLhttp://www.library.com/books/books /175 – Effective Java 2nd – Josh Bloch /952 – Windows MFC – Jeff Prosise /319 – C++ Programming – Bjarne Stroustrup /367 – UML Distilled – Martin Fowler /361 – Beginning Oracle – Tom Kyte /245 – Doman Driven Design – Eric Evans /298 – Lucene in Action – Erik Hatcher /395 – Ext GWT RIA – Grant Slender /392 – Tomcat 6 – Vivek Chopra /281 – RESTful Services – Sam RubyA Representation of the Resource is returned, and thus placing the client application in a State. The Representation contains hyperlinks to other related Resources (individual books).User clicks a hyperlink on the pageA Representation of another Resource is returned, and thus causing a Transfer of client application State This constant Transfer in client’s State through various Representations is “Representational State Transfer”
  • 6.
    RESTRoy Fielding introducedREST Architectural Style for distributed hypermedia systems
  • 7.
    What is an‘Architectural Style’?An Architectural style is way of classifying architectures based on a set of “architectural constraints”Gothic Architecture:The ‘Clustered Columns’, ‘Pointed Ribbed Vaults’ and the ‘Flying Buttresses’ makes this a Gothic Architecture
  • 8.
    REST Architectural StyleConstraintsClient-Server – clients separated from server by uniform interface
  • 9.
    Stateless – noclient context stored on server
  • 10.
    Cacheable – responsesmust define themselves as cacheable or not
  • 11.
    Layered System –intermediary servers for load balancing, shared caches and enforce security
  • 12.
    Code on Demand(optional) – customize client functionality by transferring logic (applets or javascript)
  • 13.
    Uniform Interface –(next slide) Guiding principles of REST InterfaceIdentification of Resources
  • 14.
    Individual resources areidentified in requests using URIs
  • 15.
  • 16.
    Resources are manipulatedusing a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE
  • 17.
  • 18.
    Each message includesenough information on how to process the message. Responses also indicate their cacheability.
  • 19.
    Hypermedia As TheEngine Of the Application State (HATEOAS)
  • 20.
    Related resources shouldbe identified in the representation returned by providing their URIsWhat do we gain by going REST?Conforming to the REST architectural style, will enable a distributed hypermedia system to have desirable emergent properties such as performance, scalability, simplicity, modifiability, visibility, portability and reliability.The largest known implementation of a system conforming to the REST architectural style is the WWW
  • 21.
    SOAP vs RESTSOAPCoffee RequestPOST /askCoffeePolitelyHTTP/1.1Host: www.coffee.comContent-Type: application/soap+xml; charset=utf-8Content-Length: 100<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.coffee.com/askCoffeePolitely"><m:GetCoffee> <m:NumberOfCoffees>1</m:NumberOfCoffees> </m:GetCoffee></soap:Body></soap:Envelope>REST Coffee Request GET /askCoffeePolitely/coffee?numberOfCoffees=1 HTTP/1.1Host: www.coffee.com
  • 22.
  • 23.
    Big advantage ofRESTYour REST API
  • 24.
    AgendaWhat’s REST?Quick tutorialon RESTFour guiding principles of RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
  • 25.
    JAX-RS SpecificationDefines aset of Java APIs for development of Web Services build according to the REST architectural style. Goals:POJO Based - Provides a set of annotations and associated classes/interfaces that can be used with POJOs to expose them as Web Resources. HTTP Centric - Provide clear mappings between HTTP & URI elements and corresponding API classes and annotationsFormat Independent - Provide necessary pluggability of content typesContainer Independent - Artifacts using the API will be deployable in a variety of web-tier containers
  • 26.
    JAX-RS Implementations(as quotedby some one else)there's a strange phenomenon regarding buses: you wait ages for one, then three come along at once! The same seems to be true for JAX-RS implementations. At the moment we have:Restletprobably the first REST framework, which existed prior to JAX-RSCXFwhich is a merger between XFire and Celtix (an Open Source ESB, sponsored by IONA and originally hosted at ObjectWeb) Jerseythe JAX-RS Reference Implementation from SunRESTEasyJBoss's JAX-RS project
  • 27.
    AgendaWhat’s REST?Introduction SOAPvs RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
  • 28.
    To get startedon the APIGenerate an API Key from developer portal http://developer.napster.com
  • 29.
    Signin using yournapster account (or) Signup for a new account
  • 30.
    Generate an APIKey from [Keys & Account Info] section
  • 31.
  • 32.
  • 33.
    and copy/paste yourAPI Key into the apiKey cell
  • 34.
  • 35.
    by clicking theCreateSession
  • 36.
    and copy/paste yourSession Key into sessionKey cell
  • 37.
    Now you canaccess all the REST API Services (Resources) and get their XML/JSON representationREST API ServicesPublic APISearch
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
    BillboardFull API documentationis at the Portal  http://developer.napster.com/docs/
  • 51.
    AgendaWhat’s REST?Introduction SOAPvs RESTJAX-RS Specification ImplementationsNapster REST API DemoNapster REST API ArchitectureSecurityResponse FormatCachingError HandlingVersioningContinuous Integration
  • 52.
    Napster REST APIArchitectureSecurityCachingResponse FormatError HandlingVersioningContinuous Integration
  • 53.
    Quick note:We putour Request details in ThreadLocal variables so that we don’t have to pass it around in method parametersSince tomcat reuses threads we clear it before a request is doneSecurityCachingResponse FormatError HandlingVersioningContinuous Integration
  • 54.
    Security – APIKey / Session KeyAPI Keys are
  • 55.
    Generated by DeveloperPortal per Application
  • 56.
    To be kept“SECRET”
  • 57.
    To be usedthrough Secure protocol (https://) only
  • 58.
  • 59.
  • 60.
    Generated by theApplications by calling “CreateSession” or “Login” APIs
  • 61.
    Validated for allincoming API requests (except CreateSession, Login)
  • 62.
    Can be usedin an Unsecured protocol (http)
  • 63.
    Good for only6 hours, it ExpiresSecurity ModelDevelopers or Partners can have one of more API Keys, each one mapped to an application
  • 64.
    For Selected Developersor Partners their API Key is given access to One or more Private APIs