This is a simple rest api developed over flask that receives base64 encoded data through JSON and generate the diff between them.
In order to have the service up and running you have to:
- Install virtual env to you environment. Take a look here.
- Clone this repo:
git clone https://github.com/lucrib/waes-assignment.git
- Move to the folder:
cd waes-assigngment
- Create virtualenv:
virtualenv venv
- Activate the virtualenv:
source venv/bin/activate
- Download the dependencies:
pip install -r requirements.txt
- Create the database:
python db_create.py
- Start the service:
python run.py
There are 3 endpoints available:
http://host/v1/diff/<id>/left
- Receives data to be diff-edhttp://host/v1/diff/<id>/right
- Receives data to be diff-ed on the other sidehttp://host/v1/diff/<id>
- Compares the data under the sameid
and answer back the offset and length of the diff
The left and right side expects to receive a JSON object through POST
method as follows:
{
"data": "VEVTVEVfREFUQQ=="
}
Example:
curl -i -X POST http://hortname/v1/1/left -H "Content-Type: application/json" -d '{"data": "VEVTVEVfREFUQQ=="}'
Notice: The id is informed in the url only, if the id is already in use the server will answer with 409 and a JSON message
The answer will be a JSON:
{
"id": 1,
"side": "left",
"uri": "http://hostname/v1/1/left"
}
This endpoint also accepts 3 other methods:
* GET
- Return the information of the diff side if there is information.
* PUT
- Receives the same JSON of the POST
method but will update the data.
* DELETE
- Deletes the data.
In order to get the diff-ed data, the left and right data must have been sent previously.
Example:
curl
This will answer with a JSON like this:
{
"uri": "http://localhost/v1/diff/1",
"id": 1,
"result": {
"message": "Offset: 0, Length: 6\nOffset: 18, Length: 3\n",
"code": 1
}
}
Notice: If there are more than one difference in the comparison this will come inside "message"
too.