manwaring/lambda-wrapper

Option to set `Content-Type` header for api handler

Closed this issue · 1 comments

I was curious if you had any thoughts/plans to support custom headers in addition to the defaults for api type handlers?

For example - Content-Type: application/json would be valuable for many API implementations, but I appreciate not all. I currently don't see a nice way to access/augment the headers from my application.

Thoughts?

I think that makes a lot of sense. Given that the method signature has all-optional parameters right now to support empty payloads, I'm thinking it would require passing in a full options object.

e.g. right now it looks like this:

# wrapper library
export function success(payload, replacer)

# app
return success(payload);

and would need to look like this:

# wrapper library
export function success({ payload, headers, replacer})

# app
return success({payload, headers});

which isn't quite as clean when you're calling it from an app, but obviously supports much more advanced use cases even beyond adding optional headers

it could also be a hybrid, supporting either a simple payload or a full options object

# wrapper library
export function success(payload | { payload, headers, replacer})

# app
return success(payload);
return success({payload, headers});

what do you think is the right developer experience for calling the library? I'm open to suggestions