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] Configuring request header before specifying the method #1765

Open
2 tasks done
Brunoaqu opened this issue Mar 3, 2023 · 1 comment
Open
2 tasks done

[feat] Configuring request header before specifying the method #1765

Brunoaqu opened this issue Mar 3, 2023 · 1 comment

Comments

@Brunoaqu
Copy link

Brunoaqu commented Mar 3, 2023

Configuring request header before specifying the method, or creating agent instances that keep memory of what we configured him with.

How I would like Superagent to be:

const superagent = require('superagent')

const agent = superagent(app).createAgent()

agent.set({
    accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
    refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
})

agent.get('/currentUser')

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
@ghost
Copy link

ghost commented May 12, 2023

i belive you can do something like this:

const superagent = require('superagent')

const request = superagent
  .agent(app)
  .set({ Accept: 'applicaion/json', 'x-custom': 'custom' });

const response = await request.get('/my/url');

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

No branches or pull requests

1 participant