As suggested in #3395 "Add an HTTP Accept header when downloading JSON", it would be nice if one could add user-defined HTTP headers with getJSON and getCSV, especially the case when some kind of token is needed for authorization, e.g., as described on https://docs.tcgplayer.com/docs/getting-started where a Authorization: bearer BEARER_TOKEN HTTP header is required for access.
To have this feature would be very nice. Possible implementation
func (ns *Namespace) GetJSON(headers string, urlParts ...string) (interface{}, error)
Usage in template
{{ $json := getJSON "headerKey:value, header2Key:value2 "url" }}
Example with Authorization:Bearer
{{ $header := "Authorization:Bearer " }}
{{ $token := .Site.Params.API_TOKEN }}
{{ $authHeader := printf "%s%s" $header $token }}
{{ $json := getJSON $authHeader "url"}}
I can implement this feature based on the provided function interface.
Edit:
Probably changes in GetJSON is not a good idea and would be better to have a separate function.
@roya3000,
I see your edit, but I want to make it clear to anyone reading this issue that your proposal would break the existing API by making the headers required for every invocation (ie. {{ getJSON "" $url }}). That's not going to work.
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
Most helpful comment
To have this feature would be very nice. Possible implementation
func (ns *Namespace) GetJSON(headers string, urlParts ...string) (interface{}, error)Usage in template
Example with Authorization:Bearer
I can implement this feature based on the provided function interface.
Edit:
Probably changes in GetJSON is not a good idea and would be better to have a separate function.