Junior — Middle
Have you created or supplemented APIs for integrating new features or expanding existing functionality?
sobes.tech AI
Answer from AI
Yes, I have created and enhanced APIs to integrate new features and expand existing functionality. This usually involves:
- Analyzing requirements and designing new endpoints or extending existing ones.
- Implementing controllers, services, and data models.
- Ensuring backward compatibility and documenting changes.
For example, in Java using Spring Boot, you can add a new REST endpoint like this:
@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);
}
// Adding a new method for updating a user
@PutMapping("/{id}")
public ResponseEntity<User> updateUser(@PathVariable Long id, @RequestBody User updatedUser) {
User user = userService.update(id, updatedUser);
if (user == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(user);
}
}
This approach allows expanding the API without breaking existing functionality.