Skip to content

Commit b9c9b46

Browse files
authored
Merge pull request #5 from ArmanShirzad/feature/documentation-improvements
docs: add comprehensive API reference documentation
2 parents 179d3e5 + ddce240 commit b9c9b46

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed

docs/API.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# API Reference
2+
3+
## Authentication
4+
5+
All API endpoints require authentication unless otherwise specified. Include the JWT token in the Authorization header:
6+
7+
```
8+
Authorization: Bearer <your-jwt-token>
9+
```
10+
11+
## Base URL
12+
13+
- **Development**: `http://localhost:8000/api/v1`
14+
- **Production**: `https://your-app.vercel.app/api/v1`
15+
16+
## Endpoints
17+
18+
### Authentication
19+
20+
#### POST /auth/register
21+
Register a new user account.
22+
23+
**Request Body:**
24+
```json
25+
{
26+
"email": "[email protected]",
27+
"password": "securepassword"
28+
}
29+
```
30+
31+
**Response:**
32+
```json
33+
{
34+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
35+
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
36+
"token_type": "bearer",
37+
"user": {
38+
"id": 1,
39+
"email": "[email protected]",
40+
"is_active": true,
41+
"is_verified": false,
42+
"tier": "free"
43+
}
44+
}
45+
```
46+
47+
#### POST /auth/login
48+
Authenticate user and get access token.
49+
50+
**Request Body:**
51+
```json
52+
{
53+
"email": "[email protected]",
54+
"password": "securepassword"
55+
}
56+
```
57+
58+
**Response:**
59+
```json
60+
{
61+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
62+
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
63+
"token_type": "bearer"
64+
}
65+
```
66+
67+
### QR Codes
68+
69+
#### POST /qr-codes/
70+
Create a new QR code.
71+
72+
**Request Body:**
73+
```json
74+
{
75+
"destination_url": "https://example.com",
76+
"title": "My QR Code",
77+
"description": "QR code for my website",
78+
"error_correction_level": "M",
79+
"size": 10,
80+
"border": 4,
81+
"foreground_color": "#000000",
82+
"background_color": "#FFFFFF"
83+
}
84+
```
85+
86+
**Response:**
87+
```json
88+
{
89+
"id": 1,
90+
"user_id": 1,
91+
"short_url": "abc123",
92+
"destination_url": "https://example.com",
93+
"title": "My QR Code",
94+
"description": "QR code for my website",
95+
"scan_count": 0,
96+
"created_at": "2024-12-19T10:00:00Z",
97+
"is_active": true
98+
}
99+
```
100+
101+
#### GET /qr-codes/my-codes
102+
Get all QR codes for the authenticated user.
103+
104+
**Response:**
105+
```json
106+
[
107+
{
108+
"id": 1,
109+
"short_url": "abc123",
110+
"destination_url": "https://example.com",
111+
"title": "My QR Code",
112+
"scan_count": 5,
113+
"created_at": "2024-12-19T10:00:00Z"
114+
}
115+
]
116+
```
117+
118+
### Analytics
119+
120+
#### GET /analytics/dashboard
121+
Get dashboard analytics for the authenticated user.
122+
123+
**Response:**
124+
```json
125+
{
126+
"total_scans": 150,
127+
"scans_today": 12,
128+
"unique_qr_codes": 5,
129+
"top_qr_codes": [
130+
{
131+
"content": "https://example.com",
132+
"scan_count": 45
133+
}
134+
],
135+
"device_stats": [
136+
{
137+
"device_type": "mobile",
138+
"count": 80
139+
},
140+
{
141+
"device_type": "desktop",
142+
"count": 70
143+
}
144+
]
145+
}
146+
```
147+
148+
## Error Responses
149+
150+
All error responses follow this format:
151+
152+
```json
153+
{
154+
"error": "Error type",
155+
"message": "Detailed error message",
156+
"details": "Additional error details (optional)"
157+
}
158+
```
159+
160+
### Common Error Codes
161+
162+
- `400 Bad Request` - Invalid request data
163+
- `401 Unauthorized` - Authentication required
164+
- `403 Forbidden` - Insufficient permissions
165+
- `404 Not Found` - Resource not found
166+
- `422 Unprocessable Entity` - Validation error
167+
- `429 Too Many Requests` - Rate limit exceeded
168+
- `500 Internal Server Error` - Server error
169+
170+
## Rate Limiting
171+
172+
API requests are rate limited based on user subscription tier:
173+
174+
- **Free**: 60 requests/hour
175+
- **Pro**: 1,000 requests/hour
176+
- **Business**: 5,000 requests/hour
177+
- **Enterprise**: Unlimited
178+
179+
Rate limit headers are included in responses:
180+
181+
```
182+
X-RateLimit-Limit: 1000
183+
X-RateLimit-Remaining: 999
184+
X-RateLimit-Reset: 1640995200
185+
```
186+
187+
## SDKs and Libraries
188+
189+
### Python
190+
```bash
191+
pip install qr-reader-premium-sdk
192+
```
193+
194+
```python
195+
from qr_reader_premium import QRReaderClient
196+
197+
client = QRReaderClient(api_key="your-api-key")
198+
qr_code = client.create_qr_code("https://example.com")
199+
```
200+
201+
### JavaScript
202+
```bash
203+
npm install qr-reader-premium-sdk
204+
```
205+
206+
```javascript
207+
import { QRReaderClient } from 'qr-reader-premium-sdk';
208+
209+
const client = new QRReaderClient('your-api-key');
210+
const qrCode = await client.createQRCode('https://example.com');
211+
```
212+
213+
## Webhooks
214+
215+
Configure webhooks to receive real-time notifications about QR code scans and other events.
216+
217+
### Webhook Events
218+
219+
- `qr_code.scanned` - QR code was scanned
220+
- `qr_code.created` - New QR code was created
221+
- `qr_code.updated` - QR code was updated
222+
- `user.subscribed` - User upgraded subscription
223+
224+
### Webhook Payload
225+
226+
```json
227+
{
228+
"event": "qr_code.scanned",
229+
"timestamp": "2024-12-19T10:00:00Z",
230+
"data": {
231+
"qr_code_id": 1,
232+
"scan_timestamp": "2024-12-19T10:00:00Z",
233+
"ip_address": "192.168.1.1",
234+
"user_agent": "Mozilla/5.0...",
235+
"country": "US"
236+
}
237+
}
238+
```

0 commit comments

Comments
 (0)