Amphtml: AMP-Form: add Request Headers to XHR Requests

Created on 23 Apr 2019  路  6Comments  路  Source: ampproject/amphtml

Describe the new feature or change to an existing feature you'd like to see

Need an option to add custom request headers to an AMP-FORM xhr request.

Some APIs needs that some params be set via request headers.

image

amp-form Developer Soon DevX Feature Request components

Most helpful comment

Thanks for opening this feature request issue! I'll prioritize it and we will address it accordingly

All 6 comments

Thanks for opening this feature request issue! I'll prioritize it and we will address it accordingly

What if we add a script tag to config headers, like:

<form method="POST" action-xhr="/form/echo-json/post">
        <script type="application/json">
        {
            "headers" : {
                "x-access-token" : "nononononoo"
            }
        }
        </script>
</form>

but is it possible to change, for example _x-access-token_ value via __amp-bind__?

@eduardogoncalves amp-bind would only be able to change attributes on the form element since it is not an AMP element, so it would not be possible to mutate the state.

Just a thought, but if you make the API from <input type="hidden"> with a special name value for a header, it would be bindable.

html <!-- suggestion --> <input type="hidden" name="__amp-form-header" value="x-access-token=nononononoo"> <input type="hidden" name="__amp-form-header" value="x-other-header=nononononoo" [value]="'x-other-header=' + variable">

@cvializ currently I'm using this approach with input hidden at https://gerenciador.fidoapp.com.br/ and using a proxy to add headers. But I wish to use it without a proxy.

Hope this feature can be implemented, we also have some APIs need to add a access token in request header.

One possible workaround for this is using amp-script to submit the request.

Was this page helpful?
0 / 5 - 0 ratings