How can i send headers for authentication?

Solved!
Posted in Designs by René Montes de Oca Mon May 09 2016 21:22:31 GMT+0000 (UTC)·9·Viewed 399 times

I need to submit a custom header (X-Auth-Token) with my token as the value. How can i achieve this with aping?
Jonathan Hornung
May 9, 2016

I'm not sure what you wanna do. Could you submit a jsfiddle or something else?

René Montes de Oca
May 9, 2016

Each request i submit to the REST API endpoint i must send additional headers, in this case:

  • X-Auth-Token: my-token

I thought that i could add an additional parameter on the directory like this:

<aping
        template-url="template.html"
        aping-jsonloader="[{ 'path': 'http://api.football-data.org/v1/soccerseasons'}]"
        headers="X-Auth-Token: my-token">
</aping>

I have no idea if it will work or if i should write additional code on the controller to add the headers.

Thank you very much for your quick response

Jonathan Hornung
May 9, 2016

apiNG's first idea is just to GET data. if you wanna POST data, then you need do this in a controller of your template

Jonathan Hornung
May 9, 2016

here is a list of all parameters of the built-in plugin "jsonloader": https://aping.readme.io/docs/usage#built-in-plugin-json-loader

René Montes de Oca
May 9, 2016

Thank you Jonathan, however i am not trying to POST data, i am talking about a GET request with custom headers.

I will give a look to source and try to figure it out.

Jonathan Hornung
May 11, 2016

Okay. You could send me a pull request for apiNG (https://github.com/JohnnyTheTank/apiNG) when you are done ;)

Jonathan Hornung
June 26, 2016

Hello René Montes de Oca,

now I added this feature. You can use it with apiNG version 1.4.x and higher:

<aping
        template-url="template.html"
        aping-jsonloader="[{ 'path': 'http://api.football-data.org/v1/soccerseasons', 'xAuthToken':'<YOUR_XAUTHTOKEN>'}]">
</aping>

But you could also use the new football-data.org plugin for apiNG: https://github.com/JohnnyTheTank/apiNG-plugin-footballdata

demo: http://plnkr.co/edit/a8Uj8V


Jonathan Hornung marked this as solved
René Montes de Oca
June 26, 2016

Awesome, thanks for the update Jonathan.

I will give it a try.

Jonathan Hornung
Sep 4, 2016

René Montes de Oca: does it work for you?

Markdown is allowed