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

feat: add form support #95

Merged
merged 5 commits into from
Jan 21, 2022
Merged

Conversation

DanielRamosAcosta
Copy link
Owner

@DanielRamosAcosta DanielRamosAcosta commented Jan 11, 2022

This PR adds support for sending multipart/form-data with the following API:

.sendForm({
  name: "Peter",
  info: {
    surname: "Parker",
  },
  avatar: fs.createReadStream("avatar.png"),
  gallery: [
    fs.createReadStream("img1.png"),
    fs.createReadStream("img2.png"),
    fs.createReadStream("img3.png"),
  ],
  other: undefined // these wont be sent
})

@codecov-commenter
Copy link

codecov-commenter commented Jan 11, 2022

Codecov Report

Merging #95 (7d15181) into main (cce0d07) will increase coverage by 1.96%.
The diff coverage is 97.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
+ Coverage   94.30%   96.27%   +1.96%     
==========================================
  Files           7        9       +2     
  Lines         123      161      +38     
  Branches       29       34       +5     
==========================================
+ Hits          116      155      +39     
  Misses          5        5              
+ Partials        2        1       -1     
Impacted Files Coverage Δ
src/tepper.ts 100.00% <ø> (ø)
src/TepperRunner.ts 98.30% <91.66%> (+2.22%) ⬆️
src/TepperBuilder.ts 93.18% <100.00%> (+0.32%) ⬆️
src/utils/objectToFormData.ts 100.00% <100.00%> (ø)
test/utils/expectServerToBeClosed.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cce0d07...7d15181. Read the comment docs.

@DanielRamosAcosta DanielRamosAcosta self-assigned this Jan 11, 2022
@DanielRamosAcosta DanielRamosAcosta added the enhancement New feature or request label Jan 11, 2022
Comment on lines 19 to 25
if (Array.isArray(value)) {
for (const valueElement of value) {
form.append(key, valueElement)
}

continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: may this can be refactored to a recursive function for arrays that have more than one dimension, even I don't think we could need it in a request

Copy link
Owner Author

Choose a reason for hiding this comment

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

I've been trying to refactor this, but I'm not getting into any conclusion. Maybe a good change for making a refactoring excercise at Acid Labs time

src/utils/objectToFormData.ts Outdated Show resolved Hide resolved
@DanielRamosAcosta DanielRamosAcosta merged commit cf594bf into main Jan 21, 2022
@DanielRamosAcosta DanielRamosAcosta deleted the feat/add-form-and-files-support branch January 21, 2022 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants