Code Monkey home page Code Monkey logo

python-microservices's Introduction

python-microservices

simple microservices

Your task is to build a simple microservice using the Python Flask framework. This microservice should be responsible for uploading and downloading typical types of files (txt, pdf, png, jpg, etc.).

Requirements

  1. /upload

    • Uploads one file at a time. Feel free to define what the payload looks like. You can go ahead and persist the files to the filesystem somewhere.
  2. /download

    • Retrieves and downloads a single file, using the filename as the key.
  3. We will be looking at understanding of web services fundamentals, including usage of appropriate error response. โ€” You should force a failure condition to demonstrate.

  4. We will also be looking more broadly at Python code structure, layout, and other best practices.

  5. Feel free to incorporate whatever else you feel appropriate and feasible.

  6. Finally, please provide a way to install dependencies and run/test the app.

Design

  1. http://localhost:8000/ will redict to http://localhost:8000/upload

    • This page will list all uploaded files. And you can upload a file using UI.
    • Or you can use curl to upload a file.
    curl -i -X POST -H "Content-Type: multipart/form-data" -F "file=@/path/to/file/sample.pdf" http://localhost:8000/upload
    
  2. When file upload fails, the error will show and a link to upload will be provided

    • The upload file should have an extension.
    • Only these extension will be allowed. txt, rtf, doc, docx, xls, xlsx, pdf
    • The upload file name should be unique in the download folder of server.
    • If upload file has any of the above issue, the server will show the corresponding error.
  3. Upload file using API endpoint http://localhost:8000/upload/your-upload-file-name.ext

    • You can use curl or your program to upload file
    curl -i -X POST -H "Content-Type: application/json" --data-binary "@/Users/austinjung/Documents/sample.pdf" http://localhost:8000/upload/my_upload.pdf
    
  4. You can get all file names using API http://localhost:8000/download

    • You can use curl or your program to get file names
    curl -i -X GET -H "Content-Type: application/json" http://localhost:8000/download
    
    • And the response will be
    [
        {
            "filename": "Austin-Jung_2019_resume.pdf",
            "url": "http://localhost:8000/download/Austin-Jung_2019_resume.pdf"
        },
        {
            "filename": "sample.pdf",
            "url": "http://localhost:8000/download/sample.pdf"
        }
    ]
  5. You can download a file using API http://localhost:8000/download/sample.pdf

    • You can use curl or your program to get file names
    curl -i -X GET -H "Content-Type: application/json" http://localhost:8000/download/sample.pdf --output sample.pdf
    

Deployment

  1. This project repository is https://github.com/austinjung/python-microservices

  2. The project repository is linked with Austin's Docker Cloud

  3. Clone this repository

    git clone [email protected]:austinjung/python-microservices.git
    
  4. In your docker, run the following line.

    cd python-microservices
    $ docker-compose down && docker-compose up --build -d
    

Tests

  1. At the project folder, run pytest
    cd python-microservices
    $ pytest
    

python-microservices's People

Contributors

austinjung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.