File size: 4,712 Bytes
d9a16d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# Crossword Puzzle API Specification
## Base URL
- Development: `http://localhost:3000/api`
- Production: `https://your-backend-domain.com/api`
## Authentication
No authentication required for this MVP version.
## Endpoints
### GET /topics
Retrieve all available topics for crossword generation.
**Response:**
```json
{
"topics": [
{
"id": 1,
"name": "Animals",
"description": "Creatures from the animal kingdom"
},
{
"id": 2,
"name": "Science",
"description": "Scientific terms and concepts"
}
]
}
```
**Status Codes:**
- `200 OK` - Success
- `500 Internal Server Error` - Database error
---
### POST /generate
Generate a new crossword puzzle based on selected topics and difficulty.
**Request Body:**
```json
{
"topics": ["Animals", "Science"],
"difficulty": "medium",
"gridSize": 15
}
```
**Parameters:**
- `topics` (string[]): Array of topic names to include
- `difficulty` (string): "easy" | "medium" | "hard"
- `gridSize` (number, optional): Grid size (default: 15)
**Response:**
```json
{
"puzzle": {
"id": "puzzle_123",
"grid": [
[
{ "letter": "D", "number": 1, "isBlocked": false },
{ "letter": "", "number": null, "isBlocked": true }
]
],
"clues": {
"across": [
{
"number": 1,
"clue": "Man's best friend",
"answer": "DOG",
"startRow": 0,
"startCol": 0,
"length": 3
}
],
"down": [
{
"number": 2,
"clue": "Feline pet",
"answer": "CAT",
"startRow": 0,
"startCol": 2,
"length": 3
}
]
},
"metadata": {
"difficulty": "medium",
"topics": ["Animals"],
"wordCount": 8,
"generatedAt": "2024-01-15T10:30:00Z"
}
}
}
```
**Status Codes:**
- `200 OK` - Puzzle generated successfully
- `400 Bad Request` - Invalid request parameters
- `422 Unprocessable Entity` - Unable to generate puzzle with given constraints
- `500 Internal Server Error` - Generation failed
---
### POST /validate
Validate user answers against the puzzle solution.
**Request Body:**
```json
{
"puzzleId": "puzzle_123",
"answers": {
"1_across": "DOG",
"2_down": "CAT"
}
}
```
**Response:**
```json
{
"validation": {
"isComplete": false,
"correctCount": 1,
"totalCount": 2,
"results": {
"1_across": {
"correct": true,
"expected": "DOG",
"provided": "DOG"
},
"2_down": {
"correct": false,
"expected": "CAT",
"provided": "CAR"
}
}
}
}
```
**Status Codes:**
- `200 OK` - Validation completed
- `400 Bad Request` - Invalid puzzle ID or answers format
- `404 Not Found` - Puzzle not found
- `500 Internal Server Error` - Validation failed
---
### GET /words/:topic (Admin/Development)
Retrieve all words for a specific topic. Useful for development and debugging.
**Parameters:**
- `topic` (string): Topic name
**Response:**
```json
{
"topic": "Animals",
"words": [
{
"id": 1,
"word": "DOG",
"length": 3,
"difficulty": 1,
"clues": [
{
"id": 1,
"text": "Man's best friend",
"difficulty": 1
}
]
}
]
}
```
**Status Codes:**
- `200 OK` - Words retrieved
- `404 Not Found` - Topic not found
- `500 Internal Server Error` - Database error
## Error Response Format
All error responses follow this format:
```json
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid difficulty level",
"details": {
"field": "difficulty",
"allowedValues": ["easy", "medium", "hard"]
}
}
}
```
## Rate Limiting
- Generate endpoint: 10 requests per minute per IP
- Other endpoints: 100 requests per minute per IP
## CORS Configuration
- Allowed origins: Frontend domain(s)
- Allowed methods: GET, POST, OPTIONS
- Allowed headers: Content-Type, Authorization
## Data Types
### Grid Cell
```typescript
interface GridCell {
letter: string; // Empty string for user input cells
number: number | null; // Clue number if cell starts a word
isBlocked: boolean; // True for black squares
}
```
### Clue
```typescript
interface Clue {
number: number; // Clue number
clue: string; // Clue text
answer: string; // Expected answer
startRow: number; // Starting row in grid
startCol: number; // Starting column in grid
length: number; // Word length
}
```
### Puzzle Metadata
```typescript
interface PuzzleMetadata {
difficulty: 'easy' | 'medium' | 'hard';
topics: string[];
wordCount: number;
generatedAt: string; // ISO timestamp
}
``` |