Java Spring Boot - Building a RESTful Web Service
Java Spring Boot - Building a RESTful Web Service
In REST architecture, a REST Server simply provides access to resources and REST client accesses and
modifies the resources. Here each resource is identified by URIs/ global IDs. REST uses various
representation to represent a resource like text, JSON, XML. JSON is the most popular one.
(source: https://www.tutorialspoint.com/restful/restful_introduction.htm)
Java SE Development Kit
(SDK)
1 1. Press CTRL + SHIFT + P to show the VSCode Command bar. Type in “spring initializr” and select
the “Spring Initializr: Create Maven Project…“
6
7. Next, choose “8” for the Java version
7
Initiate your Dependencies
Now you’ll choose the folder to put your Java Spring Boot template application
generated by the Initializr.
There will be a pop-up message in the lower-left corner of your VS Code screen
showing that the package generation process was successful.
Click “Open” on the prompt, to bring out the starting project we’ve just created
Start the Java Spring Boot project
• If nama provided, it will show greeting with the nama provided, if not then Dunia will be used as the
default nama
• The id will also increased automatically each time the service called
• http://localhost:8888/apakabar
{
"id": 1,
"isi": "Apa kabar, Dunia?!“
}
• http://localhost:8888/apakabar?nama=Manusia
{
"id": 2,
"isi": "Apa kabar, Manusia?!“
}
Start Coding
We’ll see on the Project Explore the path of our project, after “src\main\java”, is
following our group name and app name from before which is
“com\example\rest\greeting”.
Initilizr also auto build an java application class file using naming convention of
“<App_name>Application.java” like shown here.
• Also shown here, Initializr made the application class using the SpringBoot
dependencies that we’ve picked earlier.
• This result maybe different on each machine, but mine seem to have
port 8080 used by other service, which in turn will cause the compiler to
throw error like this:
Description:
Web server failed to start. Port 8080 was already in
use.
Action:
Identify and stop the process that's listening on
port 8080 or configure this application to listen on
another port.
• This can be rectify either by stopping the other service using the port or
by changing our own port designation. We choose the later because its’
more feasible in the real world scenario.
Compile Error
server.port:<new_port_number>
http://localhost:8888/salam
• And here’s what it looked in the Raw Data format with Pretty Print activated
http://localhost:8888/salam?name=Manusia
More questions about SpringBoot?
Thank you for sticking with this tutorial until the end.