Hi everyone ✋.
This is REST api tutorial with a simple web application example.
REST api is one of web service architecture. So lets talk about what is a web service .
Web service is a collection of open protocols and standards used for exchanging data between clients and servers.
The Web services based on REST Architecture are known as RESTful web services.
REST stands for:
REpresentational
State
Transfer
It uses HTTP Protocol.
It is widely using web based architecture in current industry.
Lets see the HTTP client calls before get start on REST api.
HTTP calls
GET - Read elements
PUT - create new element
DELETE - Remove elements
POST -Update elements
So lets learn RESTful web service with simple web example.
For this I use NetBeans IDE, Mysql database, Glass fish server and for front end developing HTML.
First create the web project using NetBeans IDE.
Click finish.
1.Go to the Services tab → Servers →GlassFish server
Then right click on the GlassFish server and click start.
after start the GlassFish server you can see an small green color arrow head appear near the GlassFish server.
See the steps below.
If you need to confirm that the server and the application run well you can right click the project and click run.
Then it should open your browser window and show as:
Then You have to create a database using mysql server.
Follow this two video tutorials which was made by me to see how to create database and connect it.
https://www.youtube.com/watch?v=W2bM7-xpJ4w&feature=youtu.be
https://www.youtube.com/watch?v=LxZQCLhJ__A
Then you have to edit your rest classes and implement GET, PUT,POST methods according to your functionalities.
Lets see the post method,
This is DataFacadeREST class
@POST
@Override
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public void create(Data entity) {
super.create(entity);
}
this super.create(entity); method used to add a new element to the database table.
Run the applcation.(before run you have to deploy it by right click the project)
Then you can see the saved data goes to the table you create at the first step .
See the result !!!
Happy coading'👍
Thankyou 👋👋👋
References: www.tutorialspoint.com
Comments
Post a Comment