3

The problem

In order to perform some requests on my API, I need to send an Authorization header on my GET and POST requests.

Do you know if it is possible to do it on AMP?

What I've tried

But I can't find a way to send the Authorization header.

ghashi
  • 1,497
  • 1
  • 13
  • 17
  • wont this be done, with javascript? to set headers you'll need to send it with javascript probably. – Muhammad Faizan Mar 19 '18 at 12:09
  • @MuhammadFaizan How can I use javascript to send requests on an AMP page? According to the documentation I can't add a – ghashi Mar 21 '18 at 23:19
  • @MuhammadFaizan I did some research and I fount this link: https://stackoverflow.com/a/39363087/3670829 It says there's a way to add custom js to your page, but I still don't know how could I perform requests based on events on my page. I'm not sure if this is allowed on AMP apps. – ghashi Mar 21 '18 at 23:21

1 Answers1

1

We can't add header to requests in AMP HTML. There are 2 solutions to this problem:

1- Fetch data in server side: We can call API with own headers in server side and haven't any limitation for that. Then server return AMP html with own fetch data.

2- Change API (or wrap API to new interface) to handle authorization with cookie: We can set cookie with Http Headers that returned from API call so If API set cookie we can perform requests and cookies automatically send with own requests and no need to handle it in client side.

Masih Jahangiri
  • 9,489
  • 3
  • 45
  • 51