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.).
-
/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.
-
/download
- Retrieves and downloads a single file, using the filename as the key.
-
We will be looking at understanding of web services fundamentals, including usage of appropriate error response. — You should force a failure condition to demonstrate.
-
We will also be looking more broadly at Python code structure, layout, and other best practices.
-
Feel free to incorporate whatever else you feel appropriate and feasible.
-
Finally, please provide a way to install dependencies and run/test the app.
-
http://localhost:8000/
will redict tohttp://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
-
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.
-
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
-
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" } ]
-
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
-
This project repository is https://github.com/austinjung/python-microservices
-
The project repository is linked with Austin's Docker Cloud
-
Clone this repository
git clone [email protected]:austinjung/python-microservices.git
-
In your docker, run the following line.
cd python-microservices $ docker-compose down && docker-compose up --build -d
- At the project folder, run pytest
cd python-microservices $ pytest