Wednesday, November 19, 2014

Webservices Example with Rest Api

Create Very Simple Jersey REST Service and Send JSON Data From Java Client

------------------------------------------------------------------------------------------------------------------------

Crunchify REST Service Example Create Very Simple Jersey REST Service and Send JSON Data From Java Client
Recently I have to pass JSON data to REST Service and did not have any simple Client handy. But created very simple Java program which read JSON data from file and sends it to REST service.
Representational State Transfer (REST) has gained widespread acceptance across the Web as a simpler alternative to SOAP- and Web Services Description Language (WSDL)-based Web services. Key evidence of this shift in interface design is the adoption of REST by mainstream Web 2.0 service providers—including Yahoo, Google, and Facebook—who have deprecated or passed on SOAP and WSDL-based interfaces in favor of an easier-to-use, resource-oriented model to expose their services. In this article, Alex Rodriguez introduces you to the basic principles of REST.
Let’s start coding this:
  1. Create RESTFul Web Service
    • Java file: CrunchifyRESTService.java
    • web.xml file
  2. Create RESTService Client
    1. CrunchifyRESTServiceClient.java file
Step 1) In Eclipse => File => New => Dynamic Web Project. Name it as “CrunchifyTutorials
Step 2) If you don’t see web.xml (deployment descriptor) under WebContent\WEB-INF\ then follow these steps.
Step 3) Open Web.xml and replace content with below contents:
Step 4: Create RESTFul service
Step 5: You may need to download these 3 files: asm-3.3.1.jarjersey-bundle-1.14.jarjson.jar
Step 6: Deploy project CrunchifyTutorials on Tomcat. Web project should be deployed without any exception.
Step 7 : Rest service should be accessible using this URL: http://localhost:8080/CrunchifyTutorials/api/crunchifyService
Step 8: Create REST Call Client.
Step 9: Now let’s run Client Program and you should see output in Tomcat Console and Local Client Console.
CrunchifyRESTServiceClient Console Output Create Very Simple Jersey REST Service and Send JSON Data From Java Client
REST service Result Create Very Simple Jersey REST Service and Send JSON Data From Java Client

2 comments:

  1. Thanks for sharing this informative content , Great work
    Leanpitch provides online training in Coaching agile transitions during this lockdown period everyone can use it wisely.

    ReplyDelete
  2. Thanks for sharing this informative content , Great work
    Leanpitch provides online training in Product prototyping during this lockdown period everyone can use it wisely.
    icp-cat training

    ReplyDelete

Java 9 and Java11 and Java17, Java 21 Features

 Java 9 and Java11 and Java17 features along with explanation and examples in realtime scenarios Here's a detailed breakdown of Java 9, ...