Hold Up!
but What Really Is An Api (application Programming Interface).

Hold Up! but What Really Is An Api (application Programming Interface).

APIs MAKES THINGS SUPER EASY LIKE SAYING THE WORLD "BOOM!"

Hello guys, for a while now, I have not been posting updates, so many stuff happened and I had to stay back for a while but trust me, am back and stronger.

In this article, we'll take a closer look at APIs (Application Programming Interfaces) and explore how they can be used to build powerful applications. Additionally, we'll walk through an example Python script that demonstrates how to make an API request to GitHub REST API and essentially get information about a particular GitHub user. APIs are powerful tools that enable software developers to access and interact with third-party services, libraries, and data sources. By leveraging APIs, developers can create applications, tools, softwares and programs that provide users with rich and dynamic functionality without having to reinvent the wheel from scratch.

Most definitely, as a Developer you'd come across this resource in your career path, this would be great knowledge for others who are starting their career path as a developer. In this article, I will also be coding in python, no need to worry, it's not a too serious code and moreso, i'd also be explaining every bit of it using comments in python, so sit back, read and enjoy.!!!

But what reallyyyyyy is an API???

Application Programming Interface, an API is like a set of instructions that tells two different computer programs how to talk to each other, a special language that helps the programs understand each other. For example, if you wanted to order a pizza online from a website that is not the one producing the Pizza but can place that order for you, the website, through API, would make a request to talk to the pizza delivery company and tell them what kind of pizza you wanted and eventually place those orders the exact way you requested. In case you still don't understand, here is another example, Google has an API that allows you to get information about maps, and Twitter has an API that lets you send tweets programmatically. Now, for some companies, they tend to hide their APIs. Which we will discuss below.

Kinds of APIs

  • Open APIs: Also known as public APIs, these are freely available to developers and can be used without any restrictions or Authentication. There are soo many out there but a very good example is the Advice API. And below, I am going to code in python on how to interact with this service.

      #!/usr/bin/env python3 
    
      # Install Requests
      # This python library is what we are going to send HTTP request to the API and then we get our response
      '''Use 
      pip install requests
      '''
    
      import requests
    
      url = "https://api.adviceslip.com/advice"  #the API we will be sending our requests to
      def randomadvice(): 
          data = requests.get(url)
          json_data = data.json()
          random_advice = json_data['slip']
          print(random_advice['advice'])
      randomadvice()
    

    Now, this code isn't something too difficult, let me explain. First of all, This code is making an API request to retrieve a random piece of advice from an API endpoint that returns advice slips in JSON format. I know why I highlighted that part because we are going to use it later.

    The first line of code uses the requests library to make a GET request to the API endpoint specified by the url variable. The response from the server is stored in the data variable.

    The second line of code uses the .json() method to parse the JSON data in the response and store it in the json_data variable. Now before we go on, API sends back responses using json method or probably xml method but the most famous is JSON method.

    Now, the third line of code selects a random advice slip from the response data by accessing the 'slip' key in the json_data dictionary.

    Finally, the last line of code prints the advice string from the selected advice slip by accessing the 'advice' key in the random_advice dictionary and then we called out our function using the randomadvice()

  • Partner APIs: These are APIs that are provided by a partner company or organization and require some form of authentication or agreement before they can be used. A typical example is the OpenAI API which u can significantly use to build your Clone of the famous ChatGPT just like I did Here. For the record, you can star, PR and fork, Thanks...

  • Internal APIs: These are APIs that are used within an organization and are not exposed to the public. They are typically used for internal applications or services.

  • Composite APIs: These are a combination of multiple data sources and services that can be accessed through a single API call.

  • Webhooks: These are event-driven notifications that allow applications to communicate with each other in real-time without having to constantly poll for changes or updates.

Ok, I have some lists of fun APIs that are mostly just for fun and can be used to add humor or geeky stuff to your existing websites and applications.

  1. Pokemon API This is an API that makes accessible all the Pokemon data in one place. Since this one does not require an API key, you can directly try this out in your browser. Look for the Pokemon Ditto https://pokeapi.co/api/v2/pokemon/ditto

  2. Chuck Norris API This is a free JSON API for hand-curated Chuck Norris facts. For example, you can retrieve a random chuck joke in JSON format — https://api.chucknorris.io/jokes/random

  3. Dog API This is the internet's most extensive collection of open-source dog pictures. For instance, try this in your browser https://dog.ceo/api/breeds/image/random

  4. REST Countries

    Thinking about building an application where you will need data about different countries of the world? Here is the API you will need. Supported by donations, this free API provides information about the country’s currency, capital, region, language, etc. Try this one out from your browser and find out more about Nigeria as a great Country https://restcountries.com/v3.1/name/Nigeria?fullText=true

So guys, that'd be all for now. Ok before I forget, Python script to get Informations about a GitHub User.

#!/bin/python

import requests

# Replace "YOUR_USERNAME" with the username of the user you want to retrieve information from
username = "PUT THE GITHUB USER NAME HERE"

# Make a request to the GitHub API to retrieve information about the user
response = requests.get(F"https://api.github.com/users/{username}")

# Check if the request was successful
if response.status_code <= 300:
    # Retrieve the JSON data from the response
    user_data = response.json()

    # Print some information about the user
    print(f"Username: {user_data['login']}")
    print(f"Name: {user_data['name']}")
    print(f"Bio: {user_data['bio']}")
    print(f"Location: {user_data['location']}")
    print(f"Followers: {user_data['followers']}")
    print(f"Following: {user_data['following']}")
    print(f"Account_ID: {user_data['id']}")
    print(f"Picture_URL: {user_data['avatar_url']}")
    print(f"Repo Count: {user_data['repos_url']}")
    print(f"Email Adress: {user_data['email']}")
    print(f"Account Created Date: {user_data['created_at']}")
    print(f"Twitter Name: {user_data['twitter_username']}")
else:
    print(f"Error: {response.status_code}")

So this is the python code I talked about earlier, through this python code, we would successfully retrieve sooo many data at once which includes name, bio, Location, followers, email address and all others. This is how powerful an API can be.

Incase you enjoyed the article, plsss leave a nice comments, it makes me feel loved and want to share more and more.

Love you guys

Peace Out!!!