Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http client support #253

Merged
merged 17 commits into from
Oct 4, 2023
Merged

Http client support #253

merged 17 commits into from
Oct 4, 2023

Conversation

reavessm
Copy link
Contributor

@reavessm reavessm commented Sep 26, 2023

Support for testing rest endpoint via sniprun

Following http file syntax

@reavessm
Copy link
Contributor Author

At least the basics works:

image

@michaelb
Copy link
Owner

Nice idea! Thank for contributing!

I'll do a more in-depth review asap

@reavessm
Copy link
Contributor Author

Thanks! I'll keep this in draft status until I get some of the other http verbs implemented but I'd love feedback, especially on other trait functions and dependency/feature related stuff

@reavessm
Copy link
Contributor Author

The http parser doesn't curently implement variable substitution, so we will need to upgrade the dependency version once Laeri/http-rest-file#1 gets merged if we want that feature

@reavessm reavessm marked this pull request as ready for review September 27, 2023 14:54
src/interpreters/Http_original.rs Outdated Show resolved Hide resolved
src/interpreters/Http_original.rs Outdated Show resolved Hide resolved
src/interpreters/Http_original.rs Outdated Show resolved Hide resolved
fn execute(&mut self) -> Result<String, SniprunError> {
let model = http_rest_file::Parser::parse(&self.code, false);

for req in model.requests.into_iter() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is meant to iterate over the several request that may appear in a snippet, it's defeated by the 'return Ok/Err' later on.

There is no way of returning 'several' Ok/Err results so there is two possibilities:

  • aggregate yourself in a way that makes sense the different request responses
  • Use the return Err(SniprunError::ReRunRanges(ranges)) trick (see the GFM interpreter, for example) to re-launch your interpreter over several snippets (i'd prefer this, unless it'd break due to semantic dependencies between request (variables?) that can't be solved in another way). In this case, have a robust "i have several requests" detection to avoid returning ReRunRanges again !

src/interpreters/Http_original.rs Outdated Show resolved Hide resolved
src/interpreters/Http_original.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@reavessm reavessm marked this pull request as draft September 28, 2023 13:56
@michaelb
Copy link
Owner

michaelb commented Sep 29, 2023

Hi @reavessm , I 'fixed' a modification you made due to an incorrect comment of mine (error_truncate stuff, sorry). Do you agree with the latest commit on the 'http' branch I just pushed ?

(it does silently fails if the resp.into_string() errors out, but I don't see that happening in the real-world, or if it does, I hope the status (not-200?) will be indicative enough)

@reavessm
Copy link
Contributor Author

Oh, I like that! Thank you! That really cleans it up. I'll add that to this PR. I'm going to reopen this for review.

I also think we shouldn't rerun anything in case somethings fails. I can see a situation where you have three REST calls that you want to execute sequentially and if the second one fails, you don't want the third to run. Especially considering this isn't naming any of the requests, I think sequential order is important

@reavessm reavessm marked this pull request as ready for review September 29, 2023 19:18
@michaelb
Copy link
Owner

michaelb commented Sep 29, 2023

I also think we shouldn't rerun anything in case somethings fails.

Fair enough

returning at the first failure should do the trick

@michaelb
Copy link
Owner

michaelb commented Oct 1, 2023

@reavessm Are you satisfied with the state of your contribution ?
As for me, this is good :-)

However, I'd like to do my own dev merge and add some cosmetics (update readme and doc) about HTTP support, so I can't give you permission to merge into master anytime you want via the review system. (Because of how most vim plugin manager works, the master branch has to be carefully synchronized with sniprun's binary releases)

Without this fix it currently becomes

    tag_to_fetch='This release and associated artifacts were created by Github Action. See the changelog [here](https://github.com/michaelb/sniprun/blob/master/CHANGELOG.md).'
@reavessm
Copy link
Contributor Author

reavessm commented Oct 1, 2023

@michaelb Yep! I can change this to be based on the dev branch. And if you need any help with docs I don't mind helping

@reavessm reavessm marked this pull request as draft October 1, 2023 17:24
@reavessm reavessm changed the base branch from master to dev October 1, 2023 17:25
@reavessm reavessm marked this pull request as ready for review October 1, 2023 17:26
@michaelb michaelb merged commit 5df93ba into michaelb:dev Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants