© 2010 IBM Corporation RESTFul Service Modelling in Rational Software Architect April, 2011
© 2010 IBM Corporation Disclaimer The information on products is intended to outline our general product direction and it should not be relied on in making a purchasing decision. The information on products is for informational purposes only and may not be incorporated into any contract. The information on the products is not a commitment, promise, or legal obligation to deliver any material, code or functionality. The development, release, and timing of any features or functionality described for our products remains at our sole discretion. Plans are based on best information available and may change in future.
© 2010 IBM Corporation REST Service Modelling What is REST? –REST Concepts Modelling Support for REST in RSA –RSA Profile Authoring –Sample REST Profile JAX-RS Support –JAXRS Modelling –RSA Transformation Extensibility –Code Generation & Reverse Engineering
© 2010 IBM Corporation REST : Representational State Transfer (REST) REST defines a set of architectural principles by which you can design Web services –focuses on a system's resources, including how resource states are addressed and transferred over HTTP. First introduced in 2000 by Roy Fielding at the University of California, Irvine, in his academic dissertation, "Architectural Styles and the Design of Network-based Software Architectures," A simpler alternative to SOAP- and Web Services Description Language (WSDL)-based Web services Has gained widespread acceptance across the Web –Adoption of REST by mainstream Web 2.0 service providers—including Yahoo, Google, and Facebook REST Web service follows four basic design principles: –Use HTTP methods explicitly. –Be stateless. –Expose directory structure-like URIs. –Representation of resource state
© 2010 IBM Corporation REST Concepts REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations –To create a resource on the server, use POST. –To retrieve a resource, use GET. –To change the state of a resource or to update it, use PUT. –To remove or delete a resource, use DELETE. REST suggests the design of web services be stateless –Doesn't require the server, while processing the request, to retrieve any kind of application context or state –A client includes within the HTTP headers and body of a request all of the parameters, context, and data needed by the server-side component to generate a response Expose directory structure-like URIs –hierarchical, rooted at a single path, and branching from it are subpaths – –
© 2010 IBM Corporation Resource URIs
© 2010 IBM Corporation Resource Representation A resource representation typically reflects the current state of a resource Has to do with the format of the data that the application and service exchange in the request/response payload or in the HTTP body {comment}
© 2010 IBM Corporation Modelling REST Domain The key abstraction of information in REST is a RESOURCE –Any information that can be named can be a resource: a document, a home page of a weblog, or a search result –A conceptual mapping to Data Entity (or actual resource) A Resource Path is a URI that identifies a particular resource Uses the concepts HTTP and URIs to retrieve or modify the state of a resource –Resource can have methods to handle HTTP request GET, PUT, POST, DELETE etc A RESOURCE can define Input/Output types –Produces/Consumes types can be specified at the individual method level as well Path between resource specifies the navigation path form a resource to a sub-resource
© 2010 IBM Corporation How to extend RSA to support Modeling REST Services?
© 2010 IBM Corporation 10 MDD enabled in RSA – UML Profiles UML in itself is not broad/detailed for all domains / platforms –UML profiles allow you to customize the language for a particular domain or method UML Profiles allow UML to be extended using –Stereotypes a type that you may apply as a property value to UML element to extend its properties and slightly alter its semantics –Tagged Values Additional properties which can be supplied E.g. Name of the Business Analyst that created that use case –Constraints Specify rules and restrictions on model elements
© 2010 IBM Corporation 11 MDD enabled in RSA – UML Profiles Profile composition palette Diagrammatic Profile composition Profile tooling generation
© 2010 IBM Corporation MDD enabled in RSA – Deploying Custom Profile Profile must be deployed before it can be applied to model. Two way to deploy a profile: –File system based deployment –Plugin based deployment In either case, it is highly recommended to have a path-map pointing to the location of the profile.
© 2010 IBM Corporation REST Profile Design
© 2010 IBM Corporation REST Domain Model
© 2010 IBM Corporation REST Modeling Tooling Support Palette support for creating domain elements Properties support for customized view
© 2010 IBM Corporation JAX-RS Support
© 2010 IBM Corporation JAX-RS Support JAX-RS: Java API for RESTful Web Services provides Java API for creating REST Services JAX-RS uses annotations to simplify the development and deployment of web services specifies the relative path for a resource specifies the HTTP request type of a resource method. specifies the returned MIME media types public class public WidgetList getDiscounted() { public WidgetResource String id) { return new WidgetResource(id); } public class WidgetResource { public WidgetResource(String id) public Widget getDetails() {} }
© 2010 IBM Corporation JAX-RS Profile REST Profile can be modified to include JAX-RS specific things –Include JAX-RS elements in REST profile if it is meant to be used in JAX-RS domain only –Create a separate profile for JAX-RS to keep REST and JAX-RS separate Additional Concepts in JAX-RS –Sub-Resource Method –Sub-Resource Locator public class public public public void modify(){…} …….. } public class public SubResource getSubResource(){…} } public class public void Operation1(){…} }
© 2010 IBM Corporation How do we generate Implementation code?
© 2010 IBM Corporation Extending Transformations A Transformation Extension allows you to tap into and contribute to an existing Transform element in a transformation For example, the UML-to-Java Transformation is composed of the following Transforms –Model Transform –Package Transform –Class Transform –Interface Transform –Generalization Transform –Property Transform –Operation Transform –… –You can extend any of these to customize the generated code
© 2010 IBM Corporation Extending Transformations Although the functionality of RSA’s built-in code transformations is complete, you may want to extend them to include generation of custom elements or conventions or to support domain specific constructs As with most features in Rational Software Architect, to extend existing transformations you use the normal Eclipse extension mechanisms, creating a plug-in and implementing specific extension points Such an extension is called a Transformation Extension
© 2010 IBM Corporation Extending Transformations - Example This extension looks for any UML keywords defined for this class in the Model and use them to add a new Javadoc tag associated with the class in the source code UML-to-Java Transformation Class Transform Extension
© 2010 IBM Corporation JAX-RS Annotation Support
© 2010 IBM Corporation Questions
© 2010 IBM Corporation Thank You!