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

Add rust target with reqwest #328

Merged
merged 6 commits into from
Jul 12, 2024
Merged

Add rust target with reqwest #328

merged 6 commits into from
Jul 12, 2024

Conversation

Benjscho
Copy link
Contributor

This PR adds a Rust target using the reqwest library. I know there was another PR (#242) to add this a while back prior to the major refactor, this completes that work with an updated implementation.

For the time being it only supports an async client, but in future that can be updated to support the blocking client later on. It also requires a few additional crates to be added to a Cargo.toml dependency file when using the generated snippets. In particular:

futures = "0.3"
reqwest = {version = "0.11.18", features = ["json", "multipart", "stream"]}
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tokio = {version = "1.30.0", features = ["full"]}
tokio-util = { version = "0.6", features = ["codec"]}

I wasn't sure how best to specify that when generating the snippets, that could be something that's passed in the the client as an option.

Most of this code was based on the Python requests library client, and I borrowed a helper implementation there. That could be generalised too for better use across the library but I just left it with the copied and modified version for now.

Either way it would be great to merge in some Rust client support. Let me know if there are any changes or refactors you'd like! I added a new helper util method to add to the last line edited, specifically so I could add semicolons.

Tested by adding fixtures and running npm run test, updated availability targets with npm test -- -u. All tests passing:

> [email protected] test
> jest

 PASS  src/targets/targets.test.ts
 PASS  src/helpers/utils.test.ts
 PASS  src/httpsnippet.test.ts
 PASS  src/targets/shell/curl/client.test.ts
 PASS  src/targets/shell/httpie/client.test.ts
 PASS  src/targets/objc/nsurlsession/client.test.ts
 PASS  src/targets/shell/wget/client.test.ts
 PASS  src/targets/go/native/client.test.ts
 PASS  src/targets/ruby/native/client.test.ts
 PASS  src/targets/node/native/client.test.ts
 PASS  src/targets/javascript/xhr/client.test.ts
 PASS  src/targets/swift/nsurlsession/client.test.ts
 PASS  src/targets/r/httr/client.test.ts
 PASS  src/targets/python/python3/client.test.ts
 PASS  src/targets/python/requests/client.test.ts
 PASS  src/helpers/escape.test.ts
 PASS  src/helpers/headers.test.ts
 PASS  src/helpers/code-builder.test.ts
 PASS  src/helpers/reducer.test.ts

Test Suites: 19 passed, 19 total
Tests:       712 passed, 712 total
Snapshots:   1 passed, 1 total
Time:        1.702 s
Ran all test suites.

@Benjscho
Copy link
Contributor Author

@filfreire Would you be able to review?

@hadrien-toma
Copy link

This feature is very interesting 😍, thank you @Benjscho for the PR 🙏 ❤️ Does someone know if something is blocking the merge? I can't wait to be able to use it haha 😅

@CLAassistant
Copy link

CLAassistant commented Jun 27, 2024

CLA assistant check
All committers have signed the CLA.

Create initial rust files to support the target. Create all of the demo
fixture files for the different request types.

These also require specific `Cargo.toml` dependencies with some features,
but I've tried to keep them fully qualified where possible. I'm not sure
yet how best to show adding dependencies to a project to enable these
features.
Start working on the reqwest conversion client after adding targets.
Completed adding Rust as a target. All of the fixtures have been tested
in a separate Rust project to verify that they build and successfully
run against the Har test endpoint.

All tests are running and passing, except for the snapshot that verifies
all available targets, not sure where to update that.
Ran the linter defined in `package.json`

All tests except snapshot for targets passing.
Update the available targets test to fix the snapshot.
@filfreire filfreire merged commit e901d61 into Kong:master Jul 12, 2024
8 checks passed
@Benjscho Benjscho deleted the add-rust branch July 27, 2024 15:26
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.

4 participants