200 likes | 446 Views
Building and using REST information services . Rion Dooley. Outline. What is REST? Why REST? Designing RESTful services Accessing RESTful services Example Demo Questions. What is REST?. Stands for REpresentational State Transfer
E N D
Building and using REST information services Rion Dooley
Outline • What is REST? • Why REST? • Designing RESTful services • Accessing RESTful services • Example • Demo • Questions
What is REST? • Stands for REpresentational State Transfer • Defined by Roy Felding (Day Software, co-founder of Apache Software Foundation) "Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.” – Roy Felding
What is REST? • It’s a way of thinking about your enterprise. • A concept, not a protocol • Applies web architecture to web services. • Model each document and process as a resource (noun) with a unique URI • Use standard HTTP actions (verbs) to interact with a resource.
What is REST? • GET: Retrieve a resource. No modification should be done. No side effects allowed. • DELETE: Remove a resource • POST: Create or update a resource • PUT: Update a resource
Why REST? • Scalable • Human and machine usable • Language agnostic • Globally accessible resources • Intuitively understandable URIs, resources, and actions.
Designing RESTful Services • Implementing a style, not a protocol • Resources rather than services • Nouns rather than verbs • Resource oriented design (ROD) • What the enterprise is instead of what the enterprise does. • Don’t reinvent the wheel!!
Accessing RESTful Services • REST is meant for interoperability. • Built on same technology as the internet. • Can be consumed in many different ways • Web browser • Web services • Lightweight clients • Command line (curl, wget) • May be used by components of an SOA, but need not be a component in an SOA.
Designing RESTful Services • Key Principals • Everything gets an ID • Link resources together • Use standard methods • Resources have multiple representations • Communicate statelessly
Example • Simple User VO service • Authenticated • Gives user-specific information about a user’s profile, resources, accounts and jobs. • Output HTML and XML responses
Example Everything gets an ID • A Resource has a unique URI. • Sample endpoints may be: • These are human-friendly for the example, but no real need for them to be so. • /profiles • /profiles/id • /resources • /resources/id • /accounts • /accounts/id
Example Use standard methods
Example Representation based on request type • Request for XML output • Request for HTML output • Could be any format you wish to support. GET /resources/forte HTTP/1.1 Host: example.com Accept: application/xml GET /resources/forte HTTP/1.1 Host: example.com Accept: text/html
Example Resources link together <resource self='http://example.com/resources/forte’> <name>forte</amount> <hostname>forte.example.com</hostname> <status>up</status> <account ref='http://example.com/accounts/1212’>1212</account> <username ref='http://example.com/profiles/jdoe’>jdoe1</username> </resource>
Example • Language and implementation details are up to the developer. • Frameworks and APIs available in most popular languages • REST is an architectural design, not a protocol, so work within your skill zone.
Links • Roy Felding’s dissertation • http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm • SOAP vs REST comparison paper • http://www.jopera.org/docs/publications/2008/restws • Security for REST web services presentation by Mark O’Neill of Vordel • http://www.vordel.com/downloads/rsa_conf_2006.pdf
Links • Popular REST Frameworks in Java • Restlet (http://www.restlet.org) • Axis 2.0 (http://ws.apache.org/axis2/0_94/rest-ws.html) • Jboss RESTEasy (http://www.jboss.org/resteasy/) • Apache CXF (http://cxf.apache.org/) • Popular REST Frameworks in other lang. • Ruby on REST(http://rubyforge.org/projects/rubyrest/) • Rest in Python (http://lukearno.com/projects/rip/) • .NET
Links • Familiar RESTful services • TeraGrid Info Services (http://info.teragrid.org/web-apps/html/index/) • Amazon Web Services (http://aws.amazon.com/) • Yahoo! Web Services (http://developer.yahoo.com/everything.html) • Google Web Services (http://code.google.com/apis/ajax/) • Accessing REST services • Python: http://developer.yahoo.com/python/python-rest.html