rubensworks / fetch-sparql-endpoint.js

A simple, lightweight module to send queries to SPARQL endpoints and retrieve their results in a streaming fashion.
MIT License
21 stars 12 forks source link

Supply custom headers #53

Closed mielvds closed 1 year ago

mielvds commented 2 years ago

Is there a way to provide custom HTTP headers (eg. for authentication)? For instance, by merging an object in https://github.com/rubensworks/fetch-sparql-endpoint.js/blob/master/lib/SparqlEndpointFetcher.ts#L180. @rubensworks If you can provide some guidance on the how, I can try a PR.

rubensworks commented 2 years ago

This is not supported yet indeed. But should be easy to add.

My recommendation would be to add an optional customHeaders?: Headers argument to ISparqlEndpointFetcherArgs, which can then be stored as a field in SparqlEndpointFetcher when passed to the constructor.

If that field is defined, it could indeed be merged with the headers here: https://github.com/rubensworks/fetch-sparql-endpoint.js/blob/master/lib/SparqlEndpointFetcher.ts#L180

We may also want to include those headers here: https://github.com/rubensworks/fetch-sparql-endpoint.js/blob/master/lib/SparqlEndpointFetcher.ts#L154-L156