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: support automatic json body for post requests #7

Merged
merged 8 commits into from
Feb 19, 2021
Merged

Conversation

danielroe
Copy link
Member

closes #4

@danielroe danielroe requested review from atinux and pi0 February 18, 2021 19:48
src/fetch.ts Outdated Show resolved Hide resolved
src/fetch.ts Outdated Show resolved Hide resolved
src/fetch.ts Outdated Show resolved Hide resolved
src/fetch.ts Outdated Show resolved Hide resolved
* test for pure object proto
* avoid try/catch
* don't add duplicate header
@codecov-io
Copy link

codecov-io commented Feb 18, 2021

Codecov Report

Merging #7 (600a59f) into main (4ab88c2) will increase coverage by 0.65%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
+ Coverage   97.61%   98.27%   +0.65%     
==========================================
  Files           4        4              
  Lines          42       58      +16     
  Branches        8       14       +6     
==========================================
+ Hits           41       57      +16     
  Misses          1        1              
Impacted Files Coverage Δ
src/fetch.ts 97.22% <100.00%> (+2.22%) ⬆️

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 4ab88c2...600a59f. Read the comment docs.

src/fetch.ts Outdated Show resolved Hide resolved
} else if ('set' in options.headers) {
;(options.headers as Headers).set(key, value)
} else {
const existingHeader = Object.keys(options.headers).find(header => header.toLowerCase() === key)
Copy link
Member

Choose a reason for hiding this comment

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

By early returning on set in case, we can dedup this line

Copy link
Member Author

Choose a reason for hiding this comment

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

not quite sure how to dedupe it - though it feels very close with the array/object syntax. how were you thinking?

Copy link
Member

Choose a reason for hiding this comment

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

By early return in first if case we can move variable to outer scope :)

@pi0
Copy link
Member

pi0 commented Feb 18, 2021

It think would be nice mentioning this feature in readme :)

@pi0 pi0 merged commit 97d0987 into main Feb 19, 2021
@pi0 pi0 deleted the automatic-post-json branch February 19, 2021 14:01
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.

Supporting JSON body
4 participants