danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
717 stars 69 forks source link

Feature Request: make linkparsers take response and request as arguments #244

Open barbich opened 3 months ago

barbich commented 3 months ago

hi (this might be more out of ignorance on my side than a topic for issue in restish)

I am trying to add a new AddLinkParser to restish to handle pagination in a vendors API (link https://cyber-risk.upguard.com/api/docs). The API in question just returns a counter to the next page token and its fairly easy to build the link the next page out of it. So for example, a query to /domains returns a JSON with next_page_token: 1000 and total_results: 15723 then the next page link would simply be /domains?page_token={next_page_token}

in m code (myparsers), as the myparsers.ParseLinks function has only the query response to work from, I have been setting the the next link by putting the link URI to "?page_token=" + b["next_page_token"].(string), leaving it to restish "links.ParseLink" (in links.go+49) function to build a complete URI using ResolveReference.

So far, so good. This has proven to be fairly easy and working as expected with one gotcha: if my original query contains any parameters, then the ResolveReference squashes those parameters making the Link URI not representative of my original query.

Hence this feature request: make linkparsers take response and request as arguments If the ParseLinks function being called would have the response and the (original) request as arguments it would allow to build more complex "next" page URIs .

Tx