mjackson / mjackson/http-client

Change default `as` in parse middleware

Open
#34 5 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.