I'm want to make a POST request to my REST API but I'm getting the error that The REST API is made in Spring I have an unexpected token :
POST Request Call :
http://localhost/users/load
Java Code:
@PostMapping(value = "/load")
public User load(@RequestBody final User user){
userRepository.save(user);
return userRepository.findByName(user.getName());
}
User Class:
@Entity
public class User {
private Long id;
private String name;
private String username;
private String password;
@Id
@GeneratedValue
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getUsername(){
return username;
}
public void setUsername(String username){
this.username = username;
}
public String setPassword(){
return password;
}
public void getPassword(){
this.password = password;
}
}
JSON data:
{
"name": "John",
"username": "randomUsername",
"password": "Password123!"
}
Error:
There was an error in evaluating the test script: SyntaxError: Unexpected token :
I expected that the request should pass but it didn't