Closed ed0xe closed 3 years ago
Thank you for your contribution! Unfortunately, I think there's a better way that doesn't require changes to web3dart
. Instead, I would just do this:
class ClientWithDefaultHeaders extends BaseClient {
final Map<String, String> additionalHeaders;
final Client inner;
ClientWithDefaultHeaders(this.additionalHeaders, this.inner);
@override
Future<StreamedResponse> send(BaseRequest request) {
additionalHeaders.forEach((key, value) {
if (!request.headers.containsKey(key)) request.headers[key] = value;
});
return inner.send(request):
}
@override
void close() => inner.close();
}
Then, you can just use a ClientWithDefaultHeaders({'x-api-key': '<YOUR-API-KEY>'}, Client())
for web3dart
which sets the right headers by default.
Hello, I am using getblock.io which recommends passing the API key in the requests headers.
'x-api-key: <YOUR-API-KEY>'
I added an additional option to pass extra headers on the instantiation of
Web3Client
Let me know if you think there is a better way.