I am pulling a response from an API using PHP to display a list of content on my WordPress website from an external service. The way they have their API set up, I need to create a loop that checks if there is a "next page" of data that I can access. The API returns a header item called "Links", with the following content:
<https://external.service.com/myusername/api/opportunities>; rel="first",<https://external.service.com/myusername/api/opportunities?before=512a7905-65a3-4845-bb8f-d2363c9e1d95>; rel="prev",<https://external.service.com/myusername/api/opportunities?after=2ab72e09-82d9-4c80-a3bb-4a2fea248695>; rel="next"
I can use the "Next" link to call the API again, which gives me the next page of data. A bit odd, but that's the way they have their API set up...not much I can do about it.
I'm assuming the best way to do this is by using a regular expression to copy the "Next" link to a variable, and create a loop which calls the link stored in the variable, updating it each time. I'm having trouble coming up with the regular expression that could do this, though. Is it possible to do without it catching the other three links as well?