0% found this document useful (0 votes)
8 views

Tutorial 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Tutorial 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

TUTORIAL 10 – CREATE

RESTFUL WEB SERVICE

 Contents:
 Introduce about web services
 Create RESTful web services with Java Spring Boot
 Prerequisites:
o Install Postman (desktop app) or Talend API Tester (Chrome extension) to
test API (Application Programming Interface). You can use alternatives.
 Introduction:
1. Formats of APIs:
o XML: eXtensible Markup Language
o JSON: JavaScript Object Notation
2. Types of web services
o SOAP: stands for Simple Object Access Protocol. SOAP is an XML based
industry standard protocol for designing and developing web services
o REST: stands for Representational State Transfer. REST is an
architectural style for developing web services
3. REST Architectural Style
o REST is a simple way to organize interactions between independent
systems. It is simpler than complex mechanisms such as RPC or SOAP
o Properties: simplicity, modifiability, visibility, portability, reliability
4. RESTful Web Service
o REST architecture-based web services
o Lightweight, maintainable, scalable
o Used to create APIs for web-based application
o The calling client can perform operations using RESTful service
o The protocol for REST is HTTP

Figure 1 - RESTful Web Service Architecture

 @GET, @PUT, @POST, @DELETE: used to specify the HTTP


request type for a method

Figure 2 - CRUD (SQL - HTTP)


 Instructions:
1. Create new Java Spring Boot project with dependencies (Refer to Tutorial 7)

Figure 4 - Project dependencies

Figure 3 – Sample project structure

2. Config MySQL connection, JPA & Hibernate (Refer to Tutorial 7)


3. Create Java class for model (entity) which acts as table in database (Refer to
Tutorial 7)
Figure 5 - Student.java

4. Create Java interface which extends JpaRepository (Refer to Tutorial 7)


5. Create Java class for Restful controller to create Restful APIs

Figure 6 - StudentController.java (1)


Figure 7 - StudentController.java (2)

6. Add sample data to database using MySQL Workbench (Refer to Tutorial 6) or


integrated MySQL database in IntelliJ (Refer to Tutorial 7)

Figure 8 - Add sample data to database

7. Run the web application then test Restful APIs with Postman
Figure 9 - View all students (GET method)
Figure 10 - View student by ID (GET method)
Figure 11 - Add new student (POST method)

Figure 12 - Update student (PUT method)


Figure 13 - Delete student (DELETE)

 TASKS:
- Add data validation for Entity & Controller then re-test with Postman
- Create similar Restful APIs for previous Spring Boot projects (Refer to
Tutorial 7+8+9)
- Compress the whole project and submit to FIT LMS with file name syntax:
FullName_StudentID_SE1_Tut10.zip

You might also like