Junior — Middle
Did you implement system interactions via REST API in your last project?
sobes.tech AI
Answer from AI
Yes, in my last project I implemented interaction between systems via REST API. I created REST controllers in Java using Spring Boot, handling HTTP requests and returning data in JSON format.
Example of a simple controller:
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/{id}")
public ResponseEntity<User> getUserById(@PathVariable Long id) {
User user = userService.findById(id);
if (user == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(user);
}
@PostMapping
public ResponseEntity<User> createUser(@RequestBody User user) {
User createdUser = userService.save(user);
return ResponseEntity.status(HttpStatus.CREATED).body(createdUser);
}
}
This approach allows systems to exchange data using standard HTTP methods, ensuring flexibility and scalability.