How to expose only writable REST api with Spring Data REST?
Hi I am trying to develop REST api using Spring boot + Spring Data JPA + Spring Data REST
I want to expose only writable part of my User ( basically no GET or GET ALL ) entity which is as below
@Entity(name = "User")
public class User implements Serializable {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
int id;
@Column
String login;
@Column
String password;
@Column
String username;
@Column
String address1;
@Column
String address2;
@Column
String city;
@Column
String state;
@Column
String zip;
@Column
String country;
@Column
String creditcard;
}
and datarepository is as below:
@RepositoryRestResource(path = "users")
public interface UserRepository extends CrudRepository<User, String> {
}
How can I achieve this?
You can override and mark methods with the @RestResource(exported = false)
.
The methods are
T findOne(ID id); // /users/<ID>
Iterable<T> findAll(); // /users
Iterable<T> findAll(Iterable<ID> ids);
You will be getting the 405 Method Not Allowed
HTTP status for all GET
requests to the repository.
Hint: It is not necessary to mark fields with the @Column
to make them reflected as database columns.