-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Detailed description
I've been using the package for a while and it's great! The repositories are a huge help to implement things quickly. However, if I need to send any dynamic headers through the repositories, I can not use them, as their methods don't accept any arguments for headers. Therefore, it's then required to re-build the DocumentClient class, which has the feature, discussed in this issue: #33
Instead of re-building the class instance, we could reuse it by forwarding headers from the Repository classes. This would improve the developer experience, for example, when using the Laravel framework. Example below.
Context
I'm currently implementing an API that has multiple "Projects" within it. Each project uses a different access token defined in the headers. Alternatively, think of it as accessing multiple different accounts. My app may need to send requests to multiple projects within the same process, which requires changing the headers. This currently isn't possible and I'm either forced to skip the Repository pattern/feature completely or I'd have to override their methods to accept the header argument. Either way, the code isn't "DRY" anymore.
Alternatively, some APIs may require other types of dynamic headers, like unique request IDs, and so on. I think this is a low-effort feature since it only requires adding a single argument, but saves a lot of time when implementing such APIs. I'd be willing to open a PR for this if such a feature is accepted.
Possible implementation
Accept a new array $headers = [] argument for every method used in repositories (default to an empty array for backward compatibility). Then forward those arguments to the underlying DocumentClient class, which already accepts them.
Your environment
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
- Package version used
2.3.2 - I'm using it in a Laravel app, which leans heavily on dependency injection. With repositories, you can simply inject them once. But since they need different headers, I need to re-create a
Clientand aDocumentClientclass, or have my own traits