Build a webservice that fulfils the documented API. The API is described below.
- Path:
/receipts/process - Method: POST
- Payload: Receipt JSON
- Response: JSON containing an id for the receipt.
Description:
Takes in a JSON receipt (see example in the examples directory) and returns a JSON object with an ID generated by your code.
The ID returned is the ID that should be passed into /receipts/{id}/points to get the number of points the receipt was awarded.
Example Response:
{ "id": "7fb1377b-b223-49d9-a31a-5a02701dd310" }
- Path:
/receipts/{id}/points - Method: GET
- Response: A JSON object containing the number of points awarded.
Description: A simple Getter endpoint that looks up the receipt by the ID and returns an object specifying the points awarded.
Example Response:
{ "points": 32 }
These rules collectively define how many points should be awarded to a receipt.
- One point for every alphanumeric character in the retailer name.
- 50 points if the total is a round dollar amount with no cents.
- 25 points if the total is a multiple of 0.25.
- 5 points for every two items on the receipt.
- If the trimmed length of the item description is a multiple of 3, multiply the price by 0.2 and round up to the nearest integer. The result is the number of points earned.
- 6 points if the day in the purchase date is odd.
- 10 points if the time of purchase is after 2:00pm and before 4:00pm.
- Install Docker(https://docs.docker.com/engine/install/)
- Install Curl(https://curl.se/download.html)
- Load the docker image -
docker load -i /path/to/saved/image.tar- Check if image is loaded successfully -
docker imagesYou should see your imported images.
- Run a Container from the Image -
docker run -d -p 8080:8000 <image_name>- Now that the server is up and running, send CURL request to local server. Change @examples/receipt2 for second receipt data.
curl -X POST "http://localhost:8000/receipts/process" -H "Content-Type: application/json" -d @examples/receipt1.jsonYou should receive a ID as a response.
- To get points
curl -X GET "http://localhost:8000/receipts/<id>/points"You should get the points corresponding to given example receipt.
- Stop the container
docker ps docker stop <container_id_or_name>
- Clone the repository
git clone <repository_url>
cd receipt-processor- Install Dependencies
pip install -r requirements.txt- Run the Flask Application
python app/main.py- Access the API endpoints using curl or postman-
curl -X POST "http://localhost:8000/receipts/process" -H "Content-Type: application/json" -d @examples/receipt1.json
curl -X GET "http://localhost:8000/receipts/<id>/points"