Session01 - APIs & Spring Core
Session01 - APIs & Spring Core
Objectives
• APIs
• RESTful APIs
• Spring Core
• Maven
API
R2S Academy - Internal Use 4
Introduction (3)
APIs
• API (Application Programming Interface) is a set of rules and protocols used to create and interact
with software or other services.
• An API defines the ways in which different software components can communicate with each other.
• This includes specifying the types of data and actions that can be performed, as well as how to send
and receive messages between applications.
Defines the
Actions
ways
Types of
data
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect
@Column(name = "last_name")
private String lastname;
@Column(name = "first_name")
private String firstname;
@Temporal(TemporalType.DATE)
@Column(name = "birth_date")
private Date birthdate;
@Column(name = “supervisor_id")
private int supervisor;
@GetMapping
public List<Employee> getAll() {
return employeeRepository.findAll();
}
@PostMapping
public Employee create(@RequestBody Employee employee) {
return employeeRepository.save(employee);
}
}
R2S Academy - Internal Use 17
RESTful APIs (12)
Build, Run, and Test
• Using Postman
public void sendWelcomeNotification(String recipient, String message) { • We can inject a concrete implementation (e.g.,
notificationService.sendNotification(recipient, message); EmailNotificationService) through the constructor.
} • This makes UserService more flexible. You can easily switch
} between different notification services by providing a different
implementation during object creation.
R2S Academy - Internal Use 26
Spring core (5)
What is DI
• Dependency Injection (DI) is a technique in which the components of a class do not create
their dependencies but are provided from the outside.
public class UserService {
// Directly create an EmailNotificationService instance
private NotificationService notificationService = new EmailNotificationService();
@Autowired
IoC
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
</dependencies>
</project>
R2S Academy - Internal Use 30
Maven (2)
What is Maven
• Maven is a project management tool which centralizes project configuration
and simplifies the build process.
• Core functionalities
- Dependency Management: It manages project dependencies (external libraries
required by your project) by fetching them from remote repositories like Maven Central.
- Build Automation: Maven automates the process of compiling source code, packaging
compiled classes into distributable formats (JARs, WARs), and running tests.
- etc…
Thank you
Contact
- Name: R2S Academy
- Email: [email protected]
Questions and Answers
- Hotline/Zalo: 0919 365 363
- Website: https://r2s.edu.vn
- Fanpage: https://www.facebook.com/r2s.tuyendung