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

Create PartParams class to allow multipart posts with JSON content and file upload at the same time #1017

Conversation

jeremyisr
Copy link
Contributor

@jeremyisr jeremyisr commented Sep 9, 2019

Description

This PR aims to make it possible to multipart POST an IO and a JSON payload at the same time.
Fixes #769

Opened after discussions in #1014

Additional Notes

Example of API which requires this :
https://developer.concur.com/api-reference/receipts/endpoints.html#endpoint-post-a-receipt

cURL data and image:

curl -v -k -X POST https://us.api.concursolutions.com/receipts/v4/users/{USER ID FROM YOUR ID TOKEN} \
-H "Authorization: Bearer {YOUR ACCESS TOKEN}" \
-H "Content-Type:multipart/form-data" \
-H "link: <http://schema.concursolutions.com/{VALIDATION SCHEMA FROM SCHEMA ENDPOINT}.schema.json>;rel=describedBy" \
-F "receipt=<{PATH TO YOUR RECEIPT JSON};type=application/json" \
-F "image=@{PATH TO YOUR IMAGE};type={FILE MIME TYPE OF YOUR IMAGE}"

@jeremyisr jeremyisr force-pushed the add-part-params-class-to-allow-multipart-posts-with-json-content-and-file-upload branch 6 times, most recently from 6f31ac4 to 0fca48f Compare September 9, 2019 17:01
Copy link
Member

@technoweenie technoweenie left a comment

Choose a reason for hiding this comment

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

Hi @jeremy-israel, thanks for addressing my PR comments. I'll try to not to throw it all away again ;)

This looks good, but I have a few suggestions below.

lib/faraday/request/multipart.rb Outdated Show resolved Hide resolved
lib/faraday/request/part_params.rb Outdated Show resolved Hide resolved
spec/faraday/request/multipart_spec.rb Outdated Show resolved Hide resolved
@jeremyisr jeremyisr force-pushed the add-part-params-class-to-allow-multipart-posts-with-json-content-and-file-upload branch 6 times, most recently from 5135f40 to 718ec9f Compare September 10, 2019 13:15
technoweenie
technoweenie previously approved these changes Sep 11, 2019
Copy link
Member

@technoweenie technoweenie left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes. I think this PR is ready to go, but there are some follow up tasks:

  • Rename Faraday::UploadIO to Faraday::FilePart
  • Update documentation for making multipart posts

iMacTia
iMacTia previously approved these changes Sep 12, 2019
Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

Clean and well structured 👍

@technoweenie
Copy link
Member

Hey, after seeing the class name in the code and docs, I'm slightly bothered by the plural ParamsPart name. It represents a single parameter of a multipart post request. A singular name like ParamPart will be more consistent with the renamed FilePart class too.

{ raw: Faraday::ParamPart.new(some_json, "application/json") }

I'm happy to make this quick change too if you don't want to bother :)

@jeremyisr jeremyisr dismissed stale reviews from iMacTia and technoweenie via 3cfa12e September 17, 2019 08:18
@jeremyisr jeremyisr force-pushed the add-part-params-class-to-allow-multipart-posts-with-json-content-and-file-upload branch from 718ec9f to 3cfa12e Compare September 17, 2019 08:18
@jeremyisr jeremyisr force-pushed the add-part-params-class-to-allow-multipart-posts-with-json-content-and-file-upload branch from 3cfa12e to 7dded89 Compare September 17, 2019 08:29
@jeremyisr
Copy link
Contributor Author

Renamed ParamsPart to ParamPart.

Copy link
Member

@technoweenie technoweenie left a comment

Choose a reason for hiding this comment

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

Thanks again. Merging this for real now 🤘

@technoweenie technoweenie merged commit 1418454 into lostisland:master Sep 17, 2019
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.

Issue with multipart/form data request with json body
3 participants