mjackson / mjackson/http-client
Change default `as` in parse middleware
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 503
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
Currently the default property for as is body, but the logic makes this undesirables, as:
https://github.com/mjackson/http-client/blob/master/modules/index.js#L205
if (as in response)
return response[as]
will by default return response.body, which may already be populated.
I run a response middleware after the parse usually, but using
parse('json'), recv(({body}) => body)
results in undefined to be output.
If I instead use
parse('json', 'jsonData'), recv(({jsonData}) => jsonData),
it works as intended, returning the JSON/JS Object.
Not sure what a better name would be; perhaps bodyData sticking by previous conventions?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/index.js around line 205 and trace the parse middleware's default as handling. Reproduce the documented parse('json'), recv(({body}) => body) case, compare it with the explicit jsonData case, and inspect the issue's naming alternatives. Done means the default parsed value no longer incorrectly resolves to an already populated response property.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100