danirod / cartero

Make HTTP requests and test APIs
https://cartero.danirod.es
GNU General Public License v3.0
397 stars 30 forks source link

`jq` integration #89

Open AlphaTechnolog opened 1 day ago

AlphaTechnolog commented 1 day ago

One of the ideas i think might be insanely cool to implement and have in cartero, is the ability to find queries parts inside cartero itself by using jq expressions... Maybe we could put like an input in the bottom of the request panel and then let the user write jq expressions there like .id and it will fetch the object id.

Maybe we could do a call to the jq binary like jq '{{expression}}' as the user types it so it gets real time, but this will also imply we add a new dependency to install, which is gonna be jq so we can access it this way, am not really sure how will this work in things like flatpak? Also, maybe we could use some jq bindings like these which am not fully sure how to integrate, but i suspect anyways will require us to rely on jq as a dependency, but we could discuss in the best way to implement something like jq integration so we can fetch certain parts of the request's response, might be awesome.

Saw this idea on the last stream of cartero development, and wanted to document it here

danirod commented 16 hours ago

Yeah, this could be very interesting and it has been discussed before on the stream.

Calling jq if available would be the easiest way to achieve this. Packaging jq into Flatpak would be a nightmare, but it seems that other people are doing it so maybe is not impossible.

Or use the binding. However, it seems that jq-sys hasn't been updated for 1.7. It seems that jaq is a thing that has been rewritten in Rust and is jq compatible. That could be another alternative.

AlphaTechnolog commented 9 hours ago

Or use the binding. However, it seems that jq-sys hasn't been updated for 1.7. It seems that jaq is a thing that has been rewritten in Rust and is jq compatible. That could be another alternative.

Oh unfortunate yeah, jaq calls my attention, however, it seems like it's only binary, like only callable from shell commands, which tbh, may make the things easier, i could just spawn it passing the input query, check output and update the panel with the output it gives from within terminal, do you know if including jaq in the crates dependencies, we could somehow make it available to be called from within shell commands? or will happen the same thing as with packaging with jq that we would have to deal with flatpak things? asking this because tbh never used too much crates and don't know if installing it will automatically expose the bin version in this case of jaq, maybe i'd need to do my own research aswell about these kind of things lmao

but anyways another thing i found was jaq_interpret which seems to be a thing that's callable from within rust code but seems to be a thing to actually consume the json instead from the code which would probably need me to do some research on how to actually get a string representation, maybe serde could do something like that though, not sure, needs research... I could try doing some experiments about this issue by creating some input with an overlay in the response panel with regular jq to make some kind of proof of concept and show it to you so we can discuss what's the best way to deal with this, maybe this could also help resolve the "cartero has no way to find in the response panel" issue lmao