sakuexe / wolt-application-2024

This is a repository for my application for Wolt. Specifically the backend application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wolt Summer 2024 Engineering Internship Application

Created by: Saku Karttunen (22.01.-31.01.2024)

Windows Disclaimer!

If you are trying to run the API on Windows, consider running inside the WSL2 terminal. Or through the Docker container. (I made it for guaranteeing compatibility between operating systems)

I built the API on my Linux machine and I cannot guarantee that it works the same way on Windows.

Assignment

The assignment was to create a simple HTTP API Endpoint that calculates the delivery fee for an order. I used Python for this assignment and some fraweworks that I list below.

The API is a single POST endpoint that takes in a JSON object as a request body and returns a JSON object as a response.

The original assignment is in it's original repository.

Used Technologies

How to run

Docker

  1. Run docker compose
docker-compose up
# or if you want to run it in the background
docker-compose up -d

The container has the port 8000 exposed, so you can access it from localhost:8000.

I added a fake client that makes randomized order requests to the API. So you can just run the program and see the results. This "client" only makes 5 orders and then stops.

Once the container is running. You can make more requests to the endpoint with curl or the fake_client.py script.

Manually

  1. Enter the virtual environment
# Linux / macOS
source venv/bin/activate
# Windows
.\venv\Scripts\activate
  1. Install the dependencies
pip install -r requirements.txt
  1. Run the server
uvicorn main:app
  1. Make a POST request to the endpoint
curl -X POST -H "Content-Type: application/json" -d '{"cart_value": 790, "delivery_distance": 2235, "number_of_items": 4, "time": "2024-01-15T13:00:00Z"}' http://127.0.0.1:8000

or use the fake client for randomized requests:

# linux / macOS
python3 fake_client.py

How to run tests

The tests are located in the tests directory. I used FastAPI's TestClient to test the API. and simple pytest compatible functions to create unit tests for all the small parts as well as more general tests for the entirety of the API.

To run the tests, run the following command in the root directory of the project:

pytest

About

This is a repository for my application for Wolt. Specifically the backend application.


Languages

Language:Python 97.7%Language:Cython 2.2%Language:PowerShell 0.1%Language:C 0.0%Language:Shell 0.0%Language:Dockerfile 0.0%