0

I have a rest web service based on Spring data rest to generate the API

this my api :

@Repository
@RepositoryRestResource(path = "cardInfos", collectionResourceRel = "cardInfos", excerptProjection = CardInfoDetailView.class)
public interface CardInfoRepository extends JpaRepository<Card, Long>, QueryDslPredicateExecutor<Card> {

    @Query("SELECT c FROM Card c")
    Page<Card> findAllProjectedBy(Pageable pageable);
}

I can get object from my service using this url using an http GET method :

http://127.0.0.1:8089/test-app/v1/cardInfos?cardNumber=1234
or : 
http://127.0.0.1:8089/test-app/v1/cardInfos?page=0&size=5

I want to set some values on the http header during the GET call and retrive those values somewhere in my service I used to use @RequestHeader HttpHeaders headers is this possible using Spring Rest Data ?

e2rabi
  • 4,728
  • 9
  • 42
  • 69
  • You can achieve the header value(s) in controller mappings (methods). Could you post your controller class where your rest mappings are defined? – sven.kwiotek Oct 30 '18 at 13:27
  • There is no controller the service is exposed using @RepositoryRestResource – e2rabi Oct 30 '18 at 13:28
  • Possible duplicate of [Custom default headers for REST API only using Spring Data REST](https://stackoverflow.com/questions/19251846/custom-default-headers-for-rest-api-only-using-spring-data-rest) – Darren Forsythe Oct 30 '18 at 13:30
  • You can have Spring wire the `HttpServletRequest` into your service and access headers via that. Otherwise, have a `ServletFilter` or Spring Interceptor intercept the request. Form here you can put the value in a `ThreadLocal` and access where required. [1] https://stackoverflow.com/q/3320674/1356423, [2] https://stackoverflow.com/a/53100895/1356423 – Alan Hay Nov 02 '18 at 15:39

0 Answers0