tomas / tomas/needle

How to send a json representation of the data but with custom Accept header?

Open
#288 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

I am doing a post to Github API which requires custom Accept header and json representation.
This is what I have

    var options = {
        headers: {
            Authorization: 'token <token>',
            Accept: 'application/vnd.github.everest-preview+json'
        },
    }
    var data = {
        event_type: "autotest",
        client_payload: {"componentToRun": "app"}
    }
    try {
        const res = await needle("post", 'https://api.github.com/repos/myrepo/reponame/dispatches',
            data,  options);
    } catch(e) {
    }

If I set json: true in options, the accept header is changed to Application/Json which is not what I want. I simply want to send the data as json without it touching my headers.

Contributor guide

No contributing guide indexed for this repository

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 by tracing how the post request handles the json option and merges or replaces the supplied Accept header. Reproduce the GitHub API example from the issue, then inspect the relevant request-option tests if available. Done means JSON is sent while the custom Accept header remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.