HTTP Request Angular

- 1 min

HTTP requests with Angular to api database (with authentication key)

So I chose angular as the framework of choice for my mvp project for this sprint and I’ll have to admit, so far I am loving it. I know I’m barely skimming the surface of what this framework has to offer, but so far I am enjoying what I have seen so far. Ok, now on to what this blog post is supposed to be about – HTTP requests using Angular, but specifically with an authentication key from the api source. I spent a few hours trying to figure this out (and thanks to our wonderful HIRs, we were able to figure out how to make it work). The api database I used for my mvp is from theysaidso.com, a database full of thousands of different kinds of quotes. I basically just wanted to get random quotes from them. Now there are a few ways to do this, but I’m going to only go over the three ways I tried. All three methods should have worked, but I think something screwy was happening on their (theysaidso.com) end that prevented the first two methods from working.

The first method is to set your authentication key directly in the headers as part of your HTTP request:

authentication key
Photo by Aralya Phinith

The second method is to set $http on your module:

$HTTP Request
Photo by Aralya Phinith

The third method is to include your authentication parameters and key directly in the url. This is also specific on how the api needs you to set it on the url as well. This was the way I was able to make it work for this specific api:

Authentication Params
Photo by Aralya Phinith

The insertion of the authentication parameters and key comes after the ‘&’ symbol in the above. And there you have it folks - the three different ways to send HTTP requests with authentication keys.

Aralya Phinith

Aralya Phinith

A Man who travels the world looking for the perfect wave

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo