A simple http microservice that loads a JSON
data structure (like the
one found below) and responds with a .zip
file whose contents are each of
the source url
named as filename
within the final .zip
archive.
The service exposes a URL and responds with data as soon as possible rather than make the user wait for the entire ZIP to be created first.
[
{
"url": "https://media.giphy.com/media/3oz8xD0xvAJ5FCk7Di/giphy.gif",
"filename": "pic001.gif"
},
{
"url": "https://media.giphy.com/media/l3vRfhFD8hJCiP0uQ/giphy.gif",
"filename": "pic002.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xG0CiDpXqYXCz6/giphy.gif",
"filename": "pic003.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xG0aignBvOhIMU/giphy.gif",
"filename": "pic004.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xwooUvMqNB1zEs/giphy.gif",
"filename": "pic005.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xyB3C126ZDDAuk/giphy.gif",
"filename": "pic006.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xSwPT41eZOvS2A/giphy.gif",
"filename": "pic007.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xAsuv5apu2cVws/giphy.gif",
"filename": "pic008.gif"
},
{
"url": "https://media.giphy.com/media/l3vR7ACppQS71ngUU/giphy.gif",
"filename": "pic009.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xSD5WkRNG1R6x2/giphy.gif",
"filename": "pic010.gif"
},
{
"url": "https://media.giphy.com/media/3oz8xzYXuCWF1IXv68/giphy.gif",
"filename": "pic011.gif"
},
{
"url": "https://media.giphy.com/media/l3vRfjcp7VMSZwbGo/giphy.gif",
"filename": "pic012.gif"
}
]
First of all, make sure you have Elixir installed by covering the official installation guide on your machine.
Once you have it, you can install and compile all dependencies by running:
mix do deps.get, deps.compile
Finally, you are able to build the project itself like:
mix compile
To start the application Phoenix server, run:
mix phx.server
Now you can visit localhost:4000
from your browser.
To prepare you application for production, you can use Dockerfile
for that. It will require you have Docker
installed locally.
To build a Docker
image, execute the following command:
docker build . -t zipper:latest
Once built, you are able to push it to a remote repository as:
docker push zipper:latest
It assumes you are authorized and logged in to a Docker
registry.
From the deployment options, you can choose for example:
Depending on your needs and complexity of your application.
There are two available endpoints for your use:
The url for the upload is:
POST /archives
The payload should be an array - a list of objects with a url
of a file to be downloaded and a filename
to save this file as.
[
{
"url": "",
"filename": ""
}
]
The result will be a payload with 202 accepted
with archive_name
that you will be able to download once it's created.
{
"archive_name": ""
}
The url for the download is:
GET /archives/<archive_name>
With the archive_name
parameter obtained from the download endpoint.
There's no need to provide any additional data nor query parameters for the request.
The result can be the following:
202 accepted
when the archive is still being prepared404 not found
when there's no archive available with the given name200 ok
with the archive to download