Skip to content

Rest API web interface developed to understand Flask and REST Api development

Notifications You must be signed in to change notification settings

imWiki/custom_flask_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Pre-Requisites

  1. Docker
  2. Any Browser to view the response for GET method
  3. Postman or Curl to push data through POST method for uploading to Imgur
  4. Git (Optional)
  5. Update the auth.ini file with your imgur secret keys before running the application

Building Docker Image

To check if you're having docker, execute command docker --version, you should see something similar below,

picture

Once repository files have been cloned/downloaded to your localhost, Please use following command to build docker image,

  1. Navigate to directory leadiq_app where repository files are downloaded

  2. Then run docker build --tag leadiq_challenge . from your terminal(Mac OS/Linux flavoured machines) or Command Prompt (Windows)

  3. Upon successful completion, you should see something similar below,

    picture

  4. You can view the successfully built image using command docker image ls

    picture

  5. Once build is successful, you can start the service with command docker run --name leadiq_app -p 5000:5000 leadiq_challenge

    picture

  6. By this time, our service has already started running, you can verify by navigating to http://localhost:5000/v1/images, you should see an empty JSON response as below,

    picture


Testing the Service

Now that our service is up and running, let's test the functionality with some URL's, I'm using curl to pass POST method to the service, you can use any app or command that you're familier with,

  1. I'm running CURL with 9 images & 1 text file to POST method of the service. a. First service will download all the images to Images folder within app setup, if URL is not downloadable, it will update the FAILED Struct with URL & Reason for failure. b. Then once all the URL's in given input array has been consumed, it will start uploading to Imgur upon successfull access_token retrieval. c. Refresh Token & Client ID/Secret are embedded into auth.ini file. d. You can use below command for your testing if you already have installed CURL in your machine,

    curl -i -H "Content-Type: application/json" -X POST -d '{"urls":["http://asppoolco.com/wp-content/uploads/2018/01/success-magazine-logo.png","https://homepages.cae.wisc.edu/~ece533/images/airplane.png","https://homepages.cae.wisc.edu/~ece533/images/arctichare.png","https://homepages.cae.wisc.edu/~ece533/images/baboon.png","https://homepages.cae.wisc.edu/~ece533/images/barbara.bmp","https://homepages.cae.wisc.edu/~ece533/images/boat.png","https://homepages.cae.wisc.edu/~ece533/images/boy.ppm","https://homepages.cae.wisc.edu/~ece533/images/cameraman.tif","https://homepages.cae.wisc.edu/~ece533/images/us021.pgm","https://homepages.cae.wisc.edu/~ece533/images/ps64int.txt"]}' http://localhost:5000/v1/images/upload
    
  2. Once request is submitted, service will immediately respone with unique random number generated within the app as below,

    picture

  3. Once Job is submitted, you can view the status on URL http://localhost:5000/v1/images/upload/{{job_id}}, Invalid job ID will return error Json as configured within the serice. Output of above job below,

    picture

  4. Hurray!! As expected, our service returned Imgur links and for failed URL, it has logged a short reason why that particular URL was ignored or failed to upload.

  5. All successfully processed images are stored within a data Struct, you can view them with http://localhost:5000/v1/images

    picture

  6. You can directly view the images with returned Imgur links as one of the sample below,

    picture

Note: I've deleted already uploaded imgur images as part of this testing from my profile, as the service directly uploads images to my user profile.

About

Rest API web interface developed to understand Flask and REST Api development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published