What are API's , what is their history , how to consume api's and use them in project

Getting to know API

  1. API stands for application programming interface
  2. An interface, that allows different systems to talk to each other without having to understand exactly what each other does

Type of API's

  1. APIs can come in many forms or shapes
  2. APIs, used for actions like turning on your camera and audio for joining a Zoom call
  3. Or they can be web APIs, used for web-focused actions such as liking images on your Instagram or fetching the latest tweets.

How Api's are operated(in simple terms)

You usually make a request for information or data, and the API returns a response with what you requested.

for example:

  1. every time you open Twitter or scroll down your Instagram feed, you’re basically making a request to the API behind that app and getting a response in return. This is also known as calling an API.

  1. web APIs have been around for quite a long time

  • In the late 1990s and early 2000s, two different design models became the norm in exposing data publicly
    • SOAP (Simple Object Access Protocol)

      is typically associated with the enterprise world, has a stricter contract-based usage, and is mostly designed around actions.

    • REST (Representational State Transfer)

      is typically used for public APIs and is ideal for fetching data from the web. It’s much lighter and closer to the HTTP specification than SOAP.

    • GraphQL

      Created by Facebook, GraphQL is a very flexible query language for APIs, where the clients decide exactly what they want to fetch from the server instead of the server deciding what to send.

  • How to consume API with python code
    • requests and APIs: A Match Made in Heaven
      • When consuming APIs with Python, there’s only one library you need: requests.

      • Installing requests module in python

        python -m pip install requests
        pip install requests

  • Calling Your First API Using Python
    • it’s time to make your first API call!

      Random User Generator API: This is a great tool for generating random user data. You can use it to generate any number of random users and associated data, and you can also specify gender, nationality, and many other filters that can be really helpful when testing apps or, in this case, APIs.

      >>> import requests
      >>> requests.get("<https://randomuser.me/api/>")
      <Response [200]>

      • Analysis of code
        • you import the requests library and then fetch (or get) data from the URL for the Random User Generator API
        • What you get instead is a Response [200], which in API terms means everything went OK.

    • If you want to see the actual data, then you can use .text from the returned Response object

      >>> import requests
      >>> response = requests.get("<https://randomuser.me/api/>")
      >>> response.text

      You managed to fetch your first random user from the Random User Generator API using Python and the requests library


Popular posts from this blog

Basic of python for beginners

basics of Margin in CSS3