Capstone Project: Loyalty Points API
By the Syncfusion DevTutorials team · Last updated
Build a complete Loyalty Points API for Brew & Bytes: validated, retry-safe, authorized, versioned, documented and monitored.
A capstone project brings together everything you learned throughout the course and applies it to a real API feature.
In this lesson, you will build the Brew & Bytes Loyalty Points API.
Customers earn points when they make purchases and redeem those points later for rewards. Along the way, you will apply concepts such as API design, validation, authentication, authorization, versioning, caching, monitoring, rate limiting, testing, and documentation.
This is not a new topic. It is a practical application of all the topics you have already learned.
Watch a Quick Loyalty API Go Wrong
The marketing team wanted a loyalty program delivered quickly. An API was written in a hurry. Press Run.
Program.cs — a loyalty API written in an hour
Several serious problems appear immediately:
Duplicate Points
Order 101 is submitted twice because the app retries the request.
The server awards: 44 points
twice.
The customer receives double rewards.
Free Points
A request claims an order amount of: ₹100000
The server trusts the value and awards: 10000 points
even though no such payment exists.
Missing Authorization
The client provides any: customerId it wants.
Anyone can:
- Earn points for another account
- Read another customer's balance
- Spend another customer's points
The API technically works, but it trusts data that should never be trusted.
In simple words: every important security, validation, and ownership rule is missing.
TL;DR
- Design resources, requests, responses, and status codes before writing code.
- Validate all incoming data.
- Take customer identity from the token, not from the request body.
- Require
Idempotency-Keyfor write operations. - Check authorization on every request.
- Return
404for balances that belong to someone else. - Return
409 Conflictwhen business rules prevent an action. - Add breaking changes in new API versions.
- Document the API with OpenAPI.
- Include a correlation id in responses and logs.
A Real-World Example
Think about a real loyalty card program in a coffee shop.
The business defines rules such as: 1 point for every ₹10 spent
The cashier:
- Verifies the customer.
- Awards points once per purchase.
- Records every transaction.
- Prevents spending more points than available.
- Explains how a balance was calculated.
Later, the business introduces: Bronze, Silver and Gold tiers.
Existing cards continue to work while new features are added.
A production loyalty API follows the same principles.
The loyalty API combines design, validation, security, versioning, documentation, testing, monitoring, and performance techniques learned throughout the course.
What You Will Learn
In this lesson, you will:
- Design a loyalty API contract.
- Validate requests properly.
- Take ownership information from tokens.
- Make writes retry-safe.
- Enforce authorization rules.
- Introduce API versioning.
- Document the API.
- Monitor and test the completed solution.
Step 1: Design and Validate
The first endpoint is:
POST /v1/loyalty/earn
Purpose:
Add loyalty points after a purchase
The endpoint requires:
- Authentication
- Input validation
- Correct status codes
Program.cs — design and validation
No Token
Response:
401 Unauthorized
Authentication is required.
Invalid Amount
Request:
{
"amount": 0
}
Response:
400 Bad Request
with:
{
"errors": {
"amount": [...]
}
}
Fake Customer ID
Request:
{
"customerId": "customer-7"
}
Token:
customer-8
Result:
Points are awarded to:
customer-8
The body value is ignored.
Valid Request
Request:
{
"amount": 120
}
Response:
201 Created
Points earned:
12
using:
1 point per ₹10 spent
Business rules belong on the server. The client sends the purchase amount. The server calculates the points. The client never decides how many points are awarded.
Step 2: Make Writes Safe and Secure
The next goal is to prevent duplicate points and unauthorized access.
Write operations require ownership validation and idempotency protection.
Program.cs — retry-safe and locked down
Prevent Duplicate Points
The first request earns: 44 points
A retry sends the same:
Idempotency-Key
Instead of processing the request again, the server returns the original result.
Balance remains: 44 points and not 88 points
Require an Idempotency Key
Missing key:
400 Bad Request
Without a key, the API cannot distinguish:
- A retry
- A brand-new request
Protect Customer Balances
Ravi attempts to:
- Read Asha's balance
- Redeem Asha's points
Both requests receive:
404 Not Found
No balance information is revealed.
Prevent Overspending
Asha has: 44 points
She attempts to spend: 100 points
Response:
409 Conflict
The business rule prevents the operation.
Valid Redemption
Spend: 30 points
Result: 44 → 14 points
Balance updates successfully.
Loyalty points represent real business value. Every write operation should verify: Who is making the request, whether the data belongs to them and whether the request is a retry. Missing any of these checks can lead to fraud or data corruption.
Step 3: Version and Document the API
The business wants loyalty tiers: Bronze, Silver and Gold
Existing clients already use:
/v1/loyalty/me
Changing the response directly would break those clients.
Instead, create a new version.
Program.cs — v1, v2 and the OpenAPI document
Version 1
Response:
{
"points": 240
}
Existing applications continue to work.
Version 2
Response:
{
"points": 240,
"tier": "silver"
}
New clients gain access to the additional feature.
OpenAPI Documentation
Endpoint:
/openapi/v1.json
Documents:
- Routes
- Request bodies
- Response models
- Status codes
- Authentication requirements
Partners can integrate without needing manual instructions.
Step 4: Test Like a Real Client
Every important scenario should become an automated test.
Program.cs — the client test suite
The tests verify:
- Earn points successfully
- Retry with the same idempotency key
- Prevent duplicate points
- Reject insufficient balances
- Prevent access to another customer's data
- Return correct status codes
- Return correlation ids
Each response includes:
X-Correlation-Id
Support teams can use that identifier to locate the exact request in logs.
Whenever you fix a bug, add a test for it. If the bug ever returns, the test will fail immediately.
Architecture of the Finished Loyalty API
Client
│
▼
Authentication
│
▼
Authorization
│
▼
Validation
│
▼
Idempotency
│
▼
Business Rules
│
▼
Database
│
▼
Logging & Monitoring
Each layer protects the system from a different type of failure.
Your Checklist
| Requirement | Related Topic |
|---|---|
| API contract design | Introduction to APIs |
| Requests and responses | HTTP Basics |
| POST, GET, and Idempotency-Key | HTTP Methods |
| Resource naming | REST API Design |
| Status codes and Problem Details | Error Handling |
| Request validation | Validation and DTOs |
| Create and read balances | CRUD APIs |
| OpenAPI documentation | OpenAPI |
| Versioned endpoints | API Versioning |
| Bearer authentication | Authentication |
| Ownership checks | Authorization |
| Tier caching | Performance and Caching |
| Earn request limits | Rate Limiting |
| Correlation IDs | Monitoring and Logging |
| Automated client tests | API Testing |
| Single API gateway | API Gateway |
| Combined customer dashboard data | GraphQL |
| Internal service communication | gRPC |
| Tier upgrade notifications | Webhooks |
Take It Home
Download the finished API from the last box as a real project, and run it on your own computer. The C# zip is an ASP.NET Core 10 project. The TypeScript zip is a Node.js project with Hono. Both include the same requests as a .http file.
Brew & Bytes loyalty points API
Where You See This
- Coffee shop loyalty systems
- Airline rewards programs
- E-commerce reward points
- Cashback and wallet systems
- Membership platforms
- Customer reward applications
These systems use the same principles:
- Authentication
- Authorization
- Validation
- Idempotency
- Monitoring
- Versioning
- Testing
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
| Customers receive duplicate points | Retries are processed twice | Require Idempotency-Key support |
| Users access other accounts | Ownership is not checked | Verify ownership from the token |
| Balances become negative | No balance validation exists | Return 409 Conflict |
| Existing applications break after new features launch | Breaking changes are made in v1 | Create v2 endpoints |
| Support cannot trace failures | No correlation id exists | Add and log X-Correlation-Id |
| Users award themselves excessive points | The server trusts client values | Calculate rewards on the server |
| Security rules are bypassed | Authorization is missing on some endpoints | Authorize every read and write request |
Exercises
What to Remember
- A good API is designed, validated, secured, versioned, documented and watched.
- Take the identity from the token. Check the owner on every request.
- Writes that move points or money must be safe to retry.
- Use
409for clashes, and use Problem Details for every error. - Add new things in a new version.
Next: API Cheat Sheet. Keep it open while you build your own APIs.