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

Add support for passing in headers to outgoing calls #552

Merged
merged 5 commits into from
Apr 5, 2024

Conversation

mrashed-dev
Copy link
Contributor

@mrashed-dev mrashed-dev commented Apr 3, 2024

Description

This PR allows you to pass in a map of additional, custom headers that can be sent to the Node SDK.

Usage

This can be used one of two ways, for all outgoing calls or on a per-call-basis.

All Calls

For all outgoing calls, you can set headers when initializing the Nylas SDK:

const nylas = new Nylas({
  apiKey: "NYLAS_API_KEY",
  headers: {
    foo: "bar"
  },
});

messages = await nylas.messages.list({
  "identifier",
}); // Will be sent with 'foo: bar' header

calendars = await nylas.calendars.list({
  "identifier",
}); // Will be sent with 'foo: bar' header

Per-call basis

For all calls to the API, we have an override object. This object is now extended to include a headers field.

const nylas = new Nylas({
  apiKey: "NYLAS_API_KEY",
});

messages = await nylas.messages.list({
  "identifier",
  overrides: {
    headers: {
      foo: "bar"
    }
  }
}); // Will be sent with 'foo: bar' header

calendars = await nylas.calendars.list({
  "identifier",
}); // Will not be sent with 'foo: bar' header

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

Copy link
Collaborator

@AaronDDM AaronDDM left a comment

Choose a reason for hiding this comment

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

Could you add a test for some of the local overrides as well? Looks like we just have a test for the header being set at the top level.

@mrashed-dev
Copy link
Contributor Author

@AaronDDM good callout, tests added.

@mrashed-dev mrashed-dev merged commit 618d8bd into main Apr 5, 2024
4 checks passed
@mrashed-dev mrashed-dev deleted the TW-2797-node-add-custom-headers-support branch April 5, 2024 13:46
mrashed-dev added a commit that referenced this pull request Apr 8, 2024
This PR adds support to the custom headers field used to attach headers to message and draft objects. Not to be confused with custom headers to Nylas API requests, completed by #552.
@mrashed-dev mrashed-dev mentioned this pull request Apr 15, 2024
mrashed-dev added a commit that referenced this pull request Apr 15, 2024
# Changelog
* Add response type to `sendRsvp` (#556)
* Add support for adding custom headers to outgoing requests (#552)
* Add support for custom headers field for drafts and messages (#553)
* Add support for setting `include_grant_scopes` for auth url generation (#554)
* Rename incorrect `type` field in `When` models to `object` (#551)
* Fix inaccuracy in `ReminderOverride` model (#555)
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.

2 participants