Junior — Middle
What HTTP method is used to perform user authentication on a web service?
sobes.tech AI
Answer from AI
The HTTP method POST is usually used to perform user authentication on a web service.
A POST request allows sending user data (such as login and password) in the request body, after which the server verifies this data and returns the authentication result (for example, an access token).
Example of using POST for authentication:
// Example controller in Spring Boot
@PostMapping("/login")
public ResponseEntity<?> authenticateUser(@RequestBody LoginRequest loginRequest) {
// login and password verification logic
// token generation and response return
}
GET and other methods are not suitable because they are not intended for transmitting confidential data in the request body.