Posts

Fetching random cat pictures using openAPI

Image
Used API https://gql.thatcopy.pw/ REST API for retrieving .jpg cat images.  Programming language and skills used Python Multiprocessing - concurrent.futures Code  We will use the url which will send us randomly chosen cat pictures. As retrieving images is a IO bound task, I'm going to use multiprocessing (you can use multi-threading because this is not a CPU bound task).  Steps to take  Retrieve json using the API  Json will be in a byte format, so we will decode it and load it to json object From the json object, extract the image source uri.  Open a new file (I'll name the file randomly) and write the image to the file.  I'll initiate download_img function with multiprocessing.  This is the complete source code  Now I've downloaded 10 images (as I queried 10 times) on my cat_pictures folder!!

What is API

 API  What is API ?  An API(Application Program Interface) is a set of routines, protocols, and tools for building software applications. Basically, an API specifies how software components should interact. API allow access to data and interact with external software components, operating systems, or microservices. Types of API  Web APIs Web APIs are APIs that can be accessed using the HTTP protocol. The API defines endpoints, and valid request and response formats.  Open APIs(or External APIs, Public APIs) These are available for developers and other users with minimal restrictions. They may require registration, and use of an API key, or may be completely open. They are intended for external users to access data or services.  Internal APIs  In contrast to open APIs, internal APIs are designed to be hidden from external users. They are used within a company to share resources. They allow different teams or section of a business to consume each other's tools, data and programs.  Pa