Skip to content

Feature request: ability to send headers dynamically through repositories #102

@rapkis

Description

@rapkis

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 Client and a DocumentClient class, or have my own traits

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions