SlideShare ist ein Scribd-Unternehmen logo
1 von 27
RESTful Web Services
   An Overview




     RAVI BUDDHARAJU
Agenda

 REST Concepts
 JAX-RS – Annotations
 Sample code
 Configure REST in Tomcat
 Unit testing the REST services
Types of Web Services

 SOAP based Web Service:
   Uses XML messages that follow the Simple Object Access
    Protocol (SOAP) standard, which defines message architecture
    and message formats.
   Operations offered by the service are written in the Web
    Services Description Language (WSDL)
 RESTful Web Services
   RESTful web services are often better integrated with HTTP.

   Do not require WSDL services and XML messages.
What are RESTful web services?

 RESTful web services are build to work best on the
  Web.
 REpresentational State Transfer(REST) is an
  architectural style, where data and functionality are
  accessed as URIs.
 Stateless, client-server, cacheable communications
  protocol, like HTTP
 Simple, Lightweight, and fast
When to use SOAP then

 Asynchronous processing and invocation: if your
 application needs a guaranteed level of reliability and
 security

 Formal contracts: if both sides (provider and consumer)
 have to agree on the exchange format

 Stateful operations: if the application needs contextual
 information and conversational state management; and to
 support those things
 (Security, Transactions, Coordination, etc).
JAX-RS

 JAX-RS is a API designed to develop apps using
  REST architecture.
 JAX-RS API uses annotations to simplify
  development. [defined in JSR311]
 Jersey is a reference implementation of JAX-RS
Resources & Representations

 Data and functionality are considered as Resources
  and accessed using URIs.
 Resources are manipulated using
  CRUD[PUT, GET, POST, DELETE] operations
 Resources are decoupled from their representations
  , so that their content can be accessed in a variety of
  formats, HTML, XML, plain text, JSON…
Stateful interactions through hyperlinks

 Every interaction with the resource is stateless.
 Stateful interactions are based on the concept of
  explicit state transfer
 State can be embedded in response messages to
  point to valid future states of the interaction.
Annotations Overview


 @Path – A relative URI path indicating where the
  Java class will be hosted
 @[GET /PUT/POST/DELETE ] – will process
  corresponding HTTP requests
 @[PathParam/QueryParam] – to extract parameters
 @[Consumes/Produces] – specify MIME types
Annotations -MIMEs support


 @Consumes - Specifies a list of media types that can
  be consumed.
 @Produces - Specifies a list of media types that can
  be produced.

    application/xml
    application/json
    text/plain
    text/html
Annotations - @Path


@Path("/users/{username}")
public class UserResource {
  @GET
  @Produces("text/xml")
  public String getUser(@PathParam("username") String
    userName) {
       ...
  }
}
Annotations - @GET
@Path("/backlog")
public class ProductBacklogResource
{
  // The Java method will process HTTP GET requests
  @GET
  // The Java method will produce content identified by the MIME Media
  // type application/json or application/xml
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
      public List<ProductBacklogItem> getProductBacklogItems() {
        return pbiManager.getPBItems();
      }
  }
Sample XML @GET response

Sample GET URL using XML -
  http://localhost:8080/apt/rest/backlog

Output:
  <productBacklogItems>
    <productBacklogItem>
        <backlogId>S1333653504620</backlogId>
        <description>desc2</description>
        <name>name2</name>
        <state>Backlog</state>
    </productBacklogItem>
    <productBacklogItem>
        <backlogId>S1333653504620</backlogId>
        ….
    </productBacklogItem>
  </productBacklogItems>
Annotations - @POST

 POST is usually used to create a resource and return a 201
  response, even though it could be used to either update or
  create.
 Return the newly created resource(URI) as the location
  header.
 Web service declares the URI for the newly created
  resource
  @POST
 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 public Response postProductBacklogItem(ProductBacklogItem item) {
   URI userUri = uriInfo.getAbsolutePathBuilder().path(item.getBacklogId()).build();
    return Response.created(userUri).build();
 }
Annotations - @PUT

 PUT must create or update a specified resource by
  sending the full content of that same resource
 Client declares the URI for the newly created resource.
 Should be idempotent

@PUT

    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JS
    ON})
    public Response putProductBacklogItem(ProductBacklogItem item) {
    …
}
Annotations - @DELETE


    @Path("/{backlogId}")
    @DELETE
    @Consumes({MediaType.APPLICATION_XML,
            MediaType.APPLICATION_JSON})
     public Response deleteProductBacklogItem(
                             @PathParam("backlogId") String backlogId) {

           //delete
}
Parameters

 @QueryParam - Extracts the value of a URI query
  parameter.
 @CookieParam Extracts the value of a cookie.
 @HeaderParam Extracts the value of a header.
 @Context Injects an instance of a supported resource

Sample
    @DefaultValue("2") @QueryParam("step") int step,
    @DefaultValue("true") @QueryParam("min-m") boolean hasMin,
    @DefaultValue("true") @QueryParam("max-m") boolean hasMax,
    @DefaultValue("true") @QueryParam("last-m") boolean hasLast,
    @DefaultValue("blue") @QueryParam("min-color") ColorParam color,
@Context

 @Context - Injects an instance of a supported
 resource
 1.    Request - request.evaluatePreconditions()

 2.    UriInfo - UriInfo provides both static and dynamic, per-
       request information, about the components of a request URI.

      @Context
      UriInfo uriInfo;
      uriInfo.getAbsolutePathBuilder().path(item.getBacklogId()).build(
       );
       uriInfo. getQueryParameters()
Jersey-Tomcat Configuration

URL when application is deployed in myContextRoot :
 http://localhost:8080/myContextRoot/rest/backlog/{name1}/

Web.xml:
   <display-name>myContextRoot</display-name>
  …
     <init-param>
     <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>org.apt.aptserver</param-value>
     </init-param>
  ..
  <servlet-mapping>
     <servlet-name>Jersey REST Service</servlet-name>
     <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
JerseyTest - WebResource

public class AppTest extends JerseyTest {
   public AppTest() throws Exception {
     super("org.apt.aptserver");
   }
  private WebResource webResource;
 @Test
  public void testProductBacklogItemListUsingPOST() {
       ClientResponse response =
       webResource.path("backlog").type(MediaType.APPLICATION_XML).put(ClientResp
       onse.class, pbi);
       GenericType<List<ProductBacklogItem>> genericType =
             new GenericType<List<ProductBacklogItem>>() {
             };
       List<ProductBacklogItem> e1 = webResource.path("backlog").get(genericType);
   }
}
Command line testing using curl - GET

 C:curl>curl -i -H "Accept: application/json"
 http://localhost:8080/apt/rest/backlog/S1
   HTTP/1.1 200 OK
   Server: Apache-Coyote/1.1
   Content-Type: application/json
   Transfer-Encoding: chunked
   Date: Wed, 02 May 2012 16:00:57 GMT

   {"backlogId":"S1","name":"name1","description":"desc1","rank":0,"e
     stimatedPoint”:null, "state":"Backlog", "createdDate":1335974456
     751, "modifiedDate":null}
Curl - POST

 curl -i -H "Accept: application/json" -H "Content-
  Type: application/json" -X POST -d @input.txt
  http://localhost:8080/apt/rest/backlog

 input.txt
   {"backlogId":"S3","name":"name3","description":"desc3"}
Recommendations

 Naming convention :
   Nouns as URI and verbs as HTTP method

 GET, PUT , DELETE should be idempotent –
  repeatable without changing state
 When a new object is created, response code 201
  should be returned
 When no content is sent back, like update case, 204
  should be returned
Sample code

 Sample code is available at
   http://code.google.com/p/agile-planning-
    tool/source/browse/trunk/src/main/java/org/apt/aptserver/
    ProductBacklogResource.java
References

 http://docs.oracle.com/javaee/6/tutorial/doc/
 http://jsr311.java.net/nonav/releases/1.1/spec/spec.
  html
 http://jersey.java.net/nonav/documentation/latest/j
  ax-rs.html
Where to go from here


 Explore reusability – sub resources
 Providers – more control on resource mapping
 Spring integration
 JerseyTest
What to do after you attend this training session:
Please complete a short Evaluation Survey
- whether you attended the live session or a recorded session
- the survey can be found on the Product Development Training SharePoint site:
 http://sharepoint.internal.gxs.com/Organizations/GSD/ProductDev/engtrng09/default.aspx

-Or you can get to it from the GXS SharePoint home page:
   Organizations
   > Global Service Delivery
     > Product Development
        > Engineering / Product Development Training
      Then Select
         “Training Evaluation Survey”
                                                   (found on the left side frame)


Product Development Training SharePoint Site
    - Includes: Documentation on training available across GXS, recordings from
      previous sessions, surveys, and other related training documents.

Weitere ähnliche Inhalte

Was ist angesagt?

REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
Soap and restful webservice
Soap and restful webserviceSoap and restful webservice
Soap and restful webserviceDong Ngoc
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA psrpatnaik
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with javaVinay Gopinath
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful ArchitectureKabir Baidya
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0Jeffrey West
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSKatrien Verbert
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptxHarry Potter
 
The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural StyleRobert Wilson
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni InturiSreeni I
 

Was ist angesagt? (20)

REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
Soap and restful webservice
Soap and restful webserviceSoap and restful webservice
Soap and restful webservice
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
 
Implementation advantages of rest
Implementation advantages of restImplementation advantages of rest
Implementation advantages of rest
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful Architecture
 
REST API Design
REST API DesignREST API Design
REST API Design
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RS
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural Style
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni Inturi
 

Ähnlich wie Overview of RESTful web services

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!Dan Allen
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all detailsgogijoshiajmer
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonJoshua Long
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Spark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSSpark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSArun Gupta
 
Felix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureFelix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureMarcel Offermans
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerKumaraswamy M
 

Ähnlich wie Overview of RESTful web services (20)

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all details
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy ClarksonMulti Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Spark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSSpark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RS
 
Felix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureFelix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the future
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RS
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
Apex REST
Apex RESTApex REST
Apex REST
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swagger
 

Kürzlich hochgeladen

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Overview of RESTful web services

  • 1. RESTful Web Services An Overview RAVI BUDDHARAJU
  • 2. Agenda  REST Concepts  JAX-RS – Annotations  Sample code  Configure REST in Tomcat  Unit testing the REST services
  • 3. Types of Web Services  SOAP based Web Service:  Uses XML messages that follow the Simple Object Access Protocol (SOAP) standard, which defines message architecture and message formats.  Operations offered by the service are written in the Web Services Description Language (WSDL)  RESTful Web Services  RESTful web services are often better integrated with HTTP.  Do not require WSDL services and XML messages.
  • 4. What are RESTful web services?  RESTful web services are build to work best on the Web.  REpresentational State Transfer(REST) is an architectural style, where data and functionality are accessed as URIs.  Stateless, client-server, cacheable communications protocol, like HTTP  Simple, Lightweight, and fast
  • 5. When to use SOAP then  Asynchronous processing and invocation: if your application needs a guaranteed level of reliability and security  Formal contracts: if both sides (provider and consumer) have to agree on the exchange format  Stateful operations: if the application needs contextual information and conversational state management; and to support those things (Security, Transactions, Coordination, etc).
  • 6. JAX-RS  JAX-RS is a API designed to develop apps using REST architecture.  JAX-RS API uses annotations to simplify development. [defined in JSR311]  Jersey is a reference implementation of JAX-RS
  • 7. Resources & Representations  Data and functionality are considered as Resources and accessed using URIs.  Resources are manipulated using CRUD[PUT, GET, POST, DELETE] operations  Resources are decoupled from their representations , so that their content can be accessed in a variety of formats, HTML, XML, plain text, JSON…
  • 8. Stateful interactions through hyperlinks  Every interaction with the resource is stateless.  Stateful interactions are based on the concept of explicit state transfer  State can be embedded in response messages to point to valid future states of the interaction.
  • 9. Annotations Overview  @Path – A relative URI path indicating where the Java class will be hosted  @[GET /PUT/POST/DELETE ] – will process corresponding HTTP requests  @[PathParam/QueryParam] – to extract parameters  @[Consumes/Produces] – specify MIME types
  • 10. Annotations -MIMEs support  @Consumes - Specifies a list of media types that can be consumed.  @Produces - Specifies a list of media types that can be produced.  application/xml  application/json  text/plain  text/html
  • 11. Annotations - @Path @Path("/users/{username}") public class UserResource { @GET @Produces("text/xml") public String getUser(@PathParam("username") String userName) { ... } }
  • 12. Annotations - @GET @Path("/backlog") public class ProductBacklogResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type application/json or application/xml @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<ProductBacklogItem> getProductBacklogItems() { return pbiManager.getPBItems(); } }
  • 13. Sample XML @GET response Sample GET URL using XML - http://localhost:8080/apt/rest/backlog Output: <productBacklogItems> <productBacklogItem> <backlogId>S1333653504620</backlogId> <description>desc2</description> <name>name2</name> <state>Backlog</state> </productBacklogItem> <productBacklogItem> <backlogId>S1333653504620</backlogId> …. </productBacklogItem> </productBacklogItems>
  • 14. Annotations - @POST  POST is usually used to create a resource and return a 201 response, even though it could be used to either update or create.  Return the newly created resource(URI) as the location header.  Web service declares the URI for the newly created resource @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response postProductBacklogItem(ProductBacklogItem item) { URI userUri = uriInfo.getAbsolutePathBuilder().path(item.getBacklogId()).build(); return Response.created(userUri).build(); }
  • 15. Annotations - @PUT  PUT must create or update a specified resource by sending the full content of that same resource  Client declares the URI for the newly created resource.  Should be idempotent @PUT @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JS ON}) public Response putProductBacklogItem(ProductBacklogItem item) { … }
  • 16. Annotations - @DELETE @Path("/{backlogId}") @DELETE @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response deleteProductBacklogItem( @PathParam("backlogId") String backlogId) { //delete }
  • 17. Parameters  @QueryParam - Extracts the value of a URI query parameter.  @CookieParam Extracts the value of a cookie.  @HeaderParam Extracts the value of a header.  @Context Injects an instance of a supported resource Sample @DefaultValue("2") @QueryParam("step") int step, @DefaultValue("true") @QueryParam("min-m") boolean hasMin, @DefaultValue("true") @QueryParam("max-m") boolean hasMax, @DefaultValue("true") @QueryParam("last-m") boolean hasLast, @DefaultValue("blue") @QueryParam("min-color") ColorParam color,
  • 18. @Context  @Context - Injects an instance of a supported resource 1. Request - request.evaluatePreconditions() 2. UriInfo - UriInfo provides both static and dynamic, per- request information, about the components of a request URI. @Context UriInfo uriInfo; uriInfo.getAbsolutePathBuilder().path(item.getBacklogId()).build( );  uriInfo. getQueryParameters()
  • 19. Jersey-Tomcat Configuration URL when application is deployed in myContextRoot : http://localhost:8080/myContextRoot/rest/backlog/{name1}/ Web.xml: <display-name>myContextRoot</display-name> … <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>org.apt.aptserver</param-value> </init-param> .. <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
  • 20. JerseyTest - WebResource public class AppTest extends JerseyTest { public AppTest() throws Exception { super("org.apt.aptserver"); } private WebResource webResource; @Test public void testProductBacklogItemListUsingPOST() { ClientResponse response = webResource.path("backlog").type(MediaType.APPLICATION_XML).put(ClientResp onse.class, pbi); GenericType<List<ProductBacklogItem>> genericType = new GenericType<List<ProductBacklogItem>>() { }; List<ProductBacklogItem> e1 = webResource.path("backlog").get(genericType); } }
  • 21. Command line testing using curl - GET  C:curl>curl -i -H "Accept: application/json" http://localhost:8080/apt/rest/backlog/S1 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/json Transfer-Encoding: chunked Date: Wed, 02 May 2012 16:00:57 GMT {"backlogId":"S1","name":"name1","description":"desc1","rank":0,"e stimatedPoint”:null, "state":"Backlog", "createdDate":1335974456 751, "modifiedDate":null}
  • 22. Curl - POST  curl -i -H "Accept: application/json" -H "Content- Type: application/json" -X POST -d @input.txt http://localhost:8080/apt/rest/backlog  input.txt  {"backlogId":"S3","name":"name3","description":"desc3"}
  • 23. Recommendations  Naming convention :  Nouns as URI and verbs as HTTP method  GET, PUT , DELETE should be idempotent – repeatable without changing state  When a new object is created, response code 201 should be returned  When no content is sent back, like update case, 204 should be returned
  • 24. Sample code  Sample code is available at  http://code.google.com/p/agile-planning- tool/source/browse/trunk/src/main/java/org/apt/aptserver/ ProductBacklogResource.java
  • 26. Where to go from here  Explore reusability – sub resources  Providers – more control on resource mapping  Spring integration  JerseyTest
  • 27. What to do after you attend this training session: Please complete a short Evaluation Survey - whether you attended the live session or a recorded session - the survey can be found on the Product Development Training SharePoint site: http://sharepoint.internal.gxs.com/Organizations/GSD/ProductDev/engtrng09/default.aspx -Or you can get to it from the GXS SharePoint home page:  Organizations > Global Service Delivery > Product Development > Engineering / Product Development Training Then Select “Training Evaluation Survey” (found on the left side frame) Product Development Training SharePoint Site - Includes: Documentation on training available across GXS, recordings from previous sessions, surveys, and other related training documents.

Hinweis der Redaktion

  1. RESTful web services are built to work best on the Web. Representational State Transfer (REST)is an architectural style that specifies constraints, such as the uniform interface, that if applied toa web service induce desirable properties, such as performance, scalability, and modifiability,that enable services to work best on the Web.
  2. @context - Request - allow a caller to determine the best matching representation variant