xxxxxxxxxx
- **Answer:** Serverless architecture abstracts server management and allows developers to focus on writing code. While microservices can be implemented in serverless environments, they are not synonymous. Serverless often involves event-driven, function-as-a-service (FaaS) deployments.
Best Practices to design Microservices:
Separate data storage for each microservice.
Maintain code at a similar level of maturity.
Separate build for each microservice.
Deploy into containers.
Treat servers as stateless.
xxxxxxxxxx
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping
public List<Employee> findAllEmployee() {
return employeeService.findAllEmployee();
}
@GetMapping("/{id}")
public Employee findEmployee(@PathVariable String id) {
return employeeService.findEmployeeById(id);
}
@PostMapping
public Employee addEmployee(@RequestBody Employee employee) {
return employeeService.addNewEmployee(employee);
}
@PutMapping("/{id}")
public Employee editEmployee(@PathVariable String id, @RequestBody Employee employee) {
return employeeService.updateEmployeeById(id, employee);
}
@DeleteMapping
public void deleteEmployee(@PathVariable String id) {
employeeService.deleteEmployeeById(id);
}
@GetMapping("/department/{departmentId}")
public List<Employee> findEmployeeByDepartmentId(@PathVariable String departmentId) {
return employeeService.findEmployeeByDepartmentId(departmentId);
}
@GetMapping("/organization/{organizationId}")
public List<Employee> findEmployeeByOrganizationId(@PathVariable String organizationId) {
return employeeService.findEmployeeByOrganizationId(organizationId);
}
}
https://www.dotnettricks.com/learn/microservices/how-do-i-start-learning-microservices