Using your first API

Cloud Computing - Data Science

Last day we learnt what is API and why we need API as a developer. And Today we will learn and use our first API in our script. Like we said we will send the request to the server in a predefined format and the server will return the information we want.

Using API

Currency API:

For the fist call we choose an API which do not need any credential to use it. This gives us the foreign exchange reference rates both current and historical data. It was published by European Central Bank. And you can learn all the requests from this API website.

For this post we will use Request library on Python to get the data from the server.

Importing libraries
API website
The request URL from the website

At first we import the libraries and check out the request format from the website.

Then we will send the request. using the get function and the predefined URL to get the data which we will parse and print.

From the printed result we can see the result is in Json format, which most of the API responses are. And the base currency is Euro. And also the data is latest, which we know from the date.

Let us find out the exchange rate of EUR to USD.

Currency Data
Data printed in the format we wanted. Like this we extract all the data from the json.

Now let us look for ways to customize our request and extract different data.

From the API website we see we can extract historical currency data by swapping the ‘latest’ with a date and we can change the base currency adding it to the URL with ‘?base=’ at the end.
like we will use the URL

getting historical data
changing base currency

From the result we can see the base currency is changed to USD and the date is changed to September 28th, 2015.

Final result
Customizing the requests and print the response

You can use this API to do a lot of projects. Like you get your script hosted on cloud which sends you currency change analysis on schedule like in a certain time everyday.

32 thoughts on “Using your first API”

  1. Definitely believe that which you stated. Your favorite justification seemed to be on the
    internet the simplest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they
    plainly do not know about. You managed to hit the nail upon the top as
    well as defined out the whole thing without having side-effects , people can take a
    signal. Will likely be back to get more. Thanks

  2. My programmer is trying to persuade me to move
    to .net from PHP. I have always disliked the idea because of
    the expenses. But he’s tryiong none the less. I’ve been using Movable-type on several websites
    for about a year and am nervous about switching to another platform.
    I have heard fantastic things about
    Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be really appreciated!

  3. This is really interesting, You are a very skilled blogger.
    I have joined your feed and look forward to seeking more of your
    great post. Also, I have shared your web site in my social networks!

  4. This design is spectacular! You obviously know how to
    keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
    I really loved what you had to say, and more than that, how
    you presented it. Too cool! 0mniartist asmr

  5. Hello there! I know this is kind of off topic but I was wondering if you knew where I could get a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having
    difficulty finding one? Thanks a lot! 0mniartist asmr

  6. Please let me know if you’re looking for a author for your blog.

    You have some really good articles and I think I would be a good asset.
    If you ever want to take some of the load off, I’d love to
    write some material for your blog in exchange for a link back to mine.

    Please send me an email if interested. Kudos!
    0mniartist asmr

  7. Thank you a bunch for sharing this with all people you
    actually know what you are talking about! Bookmarked.
    Please additionally talk over with my site =). We may
    have a hyperlink change agreement between us

  8. I do trust all of the ideas you’ve offered on your post.
    They’re really convincing and will definitely work.
    Nonetheless, the posts are too short for starters.
    May just you please lengthen them a bit from subsequent time?
    Thanks for the post.

  9. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started
    and create my own. Do you require any html coding expertise
    to make your own blog? Any help would be really appreciated!

  10. scoliosis
    A person necessarily assist to make critically posts I might state.

    That is the very first time I frequented your web page and thus far?
    I amazed with the research you made to create this actual publish amazing.
    Fantastic task! scoliosis

  11. free dating sites
    After I initially left a comment I seem to have clicked the -Notify me
    when new comments are added- checkbox and from now on whenever a
    comment is added I recieve four emails with the same comment.
    Is there a means you can remove me from that service?
    Kudos! free dating sites

  12. Aw, this was a very nice post. Taking a few minutes and
    actual effort to make a top notch article… but what
    can I say… I put things off a lot and don’t seem to get anything done.

  13. Hey There. I discovered your weblog the usage of msn. This is a really well written article.
    I’ll make sure to bookmark it and come back to read extra of your helpful
    information. Thanks for the post. I’ll definitely comeback.

  14. Wow, superb blog format! How long have you been running a blog for?
    you make blogging look easy. The whole look of your web site is great, let alone the content!

  15. Pingback: Google

  16. Hi, i think that i saw you visited my blog so i came to ?return the favor?.I am attempting to find things to enhance my
    website!I suppose its ok to use a few of your ideas!!

Leave a Comment

Your email address will not be published.