Spring Pageable object in get request from React using Axios

user3344447 :

I have an endpoint looking like this

@GetMapping("/page") Page<Event> getEventPage( @PageableDefault(page = 0, size = 20) @SortDefault(sort = "createdDateTime", direction = Sort.Direction.DESC) Pageable pageable)

How am I supposed to pass the Pageable object from my React frontend using Axios, I got this so far:

fetchEvents(pageable) {
    return axios.get("http://localhost:8080/api/events/page", pageable, this.setupAxiosInterceptors());
}

Where pageable is the last fetched page. Now it just resorts to the default values.

n9iels :

You simply do this by adding query parameters to the url. Like http://localhost:8080/api/events/page?page=1&size=20

The axios way to do this would be something like this:

const querystring = require('querystring');
axios.get('http://localhost:8080/api/events/page', querystring.stringify({ page: 1, size: 20 }));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=171245&siteId=1