Expenses Tracker API

Build an expenses tracker

2 hours
easy
9 submissions

Project Overview

Build an expenses tracker

The Expense Tracker API is a RESTful service that helps users manage expenses, set a spending budget, and define recurring expenses. It monitors total spending and automatically sends a webhook notification whenever the budget is exceeded. The project includes endpoints to manage expenses, configure recurring charges, and set up the webhook URL dynamically. It's ideal for learning how to build event-driven APIs with real-time budget tracking and external integrations.

Your submissions

No submissions yet, start by making your first submission

Detailed Project Description

The Expense Tracker API is a RESTful API designed to help users manage their personal or organizational expenses. It includes features for:

  • Tracking expenses
  • Setting and monitoring a budget
  • Configuring recurring expenses
  • Triggering webhook notifications when the budget is exceeded

This project also integrates with a Webhook Test Server, which receives alerts when expenses go over the defined budget.


🚀 Features

  • 📦 Add, retrieve, and manage expenses
  • 🎯 Set a budget
  • 🔁 Add recurring expenses
  • 📬 Trigger real-time webhook notifications when budget is exceeded

📘 API Endpoints

🔧 POST /setup

  • Purpose: Set the webhook URL to receive notifications.
  • Request Body:
{ "webhookUrl": "http://localhost:5555" }
  • Responses:
    • 200 OK – Webhook URL accepted
    • 400 Bad Request – Invalid URL format

💰 POST /expenses

  • Purpose: Add a new expense.
  • Request Body:
{ "amount": 50, "category": "food" }
  • Responses:
    • 201 Created

If the total of all expenses exceeds the current budget, a notification is sent to the webhook.


📋 GET /expenses

  • Purpose: Retrieve all recorded expenses.
  • Response:
{ "expenses": [ { "amount": 50, "category": "food", "timestamp": 1711492393000 } ] }

🎯 POST /budget

  • Purpose: Set or update the budget limit.
  • Request Body:
{ "amount": 100 }
  • Response:
{ "message": "Budget set successfully" }

🔁 POST /recurring

  • Purpose: Add a recurring expense.
  • Request Body:
{ "amount": 20, "category": "subscription", "intervalInSeconds": 5 }
  • Response:
{ "message": "Recurring expense added" }

Each recurring expense is added to /expenses on a repeating interval. If cumulative expenses exceed the budget, a notification is sent.


🔁 GET /recurring

  • Purpose: Retrieve all recurring expenses.
  • Response:
{ "recurringExpenses": [ { "amount": 20, "category": "subscription", "intervalInSeconds": 5, "lastRun": 1711492393000 } ] }

📬 Webhook Integration

When expenses exceed the set budget (either by direct or recurring additions), a POST request is sent to:

POST <webhookUrl>/notifications

Payload:

{ "message": "Budget exceeded", "total": 210, "expenses": [ { "amount": 50, "category": "food", "timestamp": 1711492393000 }, { "amount": 160, "category": "electronics", "timestamp": 1711492493000 } ] }

✅ Completion Criteria

Your implementation will be evaluated against the following:

  • Correctly setting up the webhook via /setup
  • Validating and rejecting malformed webhook URLs
  • Adding and retrieving expenses
  • Setting and enforcing budget limits
  • Sending budget-exceeded notifications to the webhook
  • Managing recurring expenses and ensuring they run at proper intervals
  • Triggering notifications from recurring expense overflow

Project Completion Criteria

  • The system should allow users to initialize the API with a valid webhook URL via POST /setup.
  • The system should return a 400 Bad Request when provided an invalid webhook URL.
  • The system should allow adding a single expense via POST /expenses and store it internally.
  • The system should allow retrieving all expenses using GET /expenses.
  • The system should allow users to set a budget via POST /budget.
  • When the total expenses exceed the set budget, the system should send a notification to the configured webhook URL.
  • The system should not send a webhook notification if the budget is not exceeded.
  • The system should support adding a recurring expense via POST /recurring with intervalInSeconds as a trigger interval.
  • Recurring expenses should automatically be added to the expense list over time.
  • Recurring expenses should be included in the webhook notifications when they cause the budget to be exceeded.
  • The system should expose existing recurring expenses via GET /recurring.
  • All responses must match the expected structure defined in the test suite and include appropriate status codes and messages.