RESTful API – CRUD Operations -Step by Step Guide
Tools and Technologies used
- Database -Oracle (You can use any DB)
- Jersey – JAX-RS API 2
- SOAP UI for testing
- Apache Tomcat Application. (You can use any Application Server)
Methods used in a service class for performing CRUD operations
@POST – Create
@GET – Read
@ PUT -Update
- Knowledge of JAVA Programming language
- Application Server basics
- DDL basics
- Knowledge of Schema languages.
Create Entities, Download Resources and Configure.
- Create an entity in DB on which CRUD operation is going to perform.
CREATE TABLE <Your Table Name> (
<Columns> VARCHAR (20) PRIMARY KEY,
<Columns> VARCHAR (20),
<Columns> VARCHAR2(40) NOT NULL,);
- Download Apache bundle from here, and Jersey bundle from here
- Configure your apache server connector port to avoid conflict with default port; that might have been used by other programs, to run into your desired port.
<Connector port=”9999″ protocol=”HTTP/1.1″ connectionTimeout=”20000″ redirectPort=”8443″ />
- Write a schema with request and response attributes. Write your elements name exactly same as your DB columns. This way it will be easier to relate when we perform xml to java object conversion
Create a simple Dynamic project and run it on the server.
- Convert XSD schema to java objects. Use xjc tool for conversion, this is quick and easy.
- Now create a Dynamic Project in Eclipse. Create a package called “generated” and put all the classes generated from XSD in there.
- Put all the jersey jars (Downloaded in step 1) in lib folder.
- Configure App to run in Tomcat server. You can do this from eclipse. Go to Windows > Preferences
- Write a simple index.html – This will be displayed once the server is successfully run.
<title>Insert title here</title>
</head><body>Welcome to RESTful API </body>
- Deploy the project – Right click and Run as >Run on the Server.
- Your application is running on the server.