java - Setting object in http get request -
i writing client side java program pageable spring data resource repository api of format:
public page<person> findbycountry(..., pageable pageable);
i have created pageable request of format
pageable pageable = new pagerequest(1, 40, new sort("name"));
however, know how can set pageable http client
. using httpget
, httppost
.
i googled bit , found links using spring rest controller. can not using apache http client? springs hateoas seems option. mean adding jar client project. question of how set payload on request?
additionally, if there better approaches let me know. want loop through pages till data exhausted.
thanks.
i not sure if going suggest best approach how go it. since cannot have reference spring dependent object i.e pageable in lean client without adding spring dependency client may want send pagerequest details http query parameters http api , loop on technology independent pagewrapper results shown below.
api signature
public pagewrapper findbycountry(..., int page, int size, string sortby, string sortdirection);
pagewrapper:
list<t> items; int currentpage; int totalpages; int totalitems; boolean islast;
api code:
pageable nextpageable = new pagerequest(page, size, new sort(sortby)); page<person> personspage = countryservice.findbycountry(.., nextpageable); if(null != personspage){ pagewrapper<person> pagewrapper = new pagewrapper<>(); pagewrapper.setitems(personspage.getcontent()); pagewrapper.settotalpages(personspage.gettotalpages()); pagewrapper.settotalitems(personspage.gettotalelements()); pagewrapper.setcurrentpage(personspage.getnumber()) pagewrapper.setislast(personspage.islast()); return pagewrapper }
client code:
pagewrapper page = null; { map<string, object> parammap = new hashmap<>(); parammap.put("page", index++); parammap.put("size", size); parammap.put("sortby", "name"); page = (pagewrapper) httpclient.get(requesturi, parammap); process(page); }while(!page.getislast())
Comments
Post a Comment