You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 1, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+174-2Lines changed: 174 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -290,6 +290,167 @@ Query Results (JSON):
290
290
]
291
291
```
292
292
293
+
## API Design
294
+
295
+
### Overview
296
+
297
+
The Text2SQL Analytics System exposes a RESTful API built with **FastAPI** that converts natural language queries into SQL and executes them against a PostgreSQL database. The API includes built-in security features, rate limiting, and comprehensive error handling.
298
+
299
+
### Base URL
300
+
301
+
```
302
+
http://localhost:8000
303
+
```
304
+
305
+
### Authentication & Security
306
+
307
+
-**Rate Limiting**: 5 requests per 10 seconds per IP address
308
+
-**Request Timeout**: Monitored via `X-Process-Time` header
309
+
-**SQL Injection Protection**: Built-in query validation and sanitization
310
+
-**Error Handling**: Structured error responses with appropriate HTTP status codes
311
+
312
+
### Endpoints
313
+
314
+
#### 1. Health Check
315
+
316
+
**GET**`/`
317
+
318
+
Returns the API health status.
319
+
320
+
**Response:**
321
+
322
+
```json
323
+
{
324
+
"status": "ok",
325
+
"message": "Text2SQL API running."
326
+
}
327
+
```
328
+
329
+
#### 2. Generate and Execute SQL
330
+
331
+
**POST**`/generate-sql`
332
+
333
+
Converts natural language to SQL, validates the query, and executes it against the database.
334
+
335
+
**Request Body:**
336
+
337
+
```json
338
+
{
339
+
"question": "Show all orders shipped in 1997"
340
+
}
341
+
```
342
+
343
+
**Response Schema:**
344
+
345
+
```json
346
+
{
347
+
"sql_query": "string", // Raw SQL generated by Gemini
348
+
"sanitized_query": "string", // SQL after sanitization
349
+
"validate_query": "string", // Final validated SQL
350
+
"result_json": "string"// Query results as JSON string
351
+
}
352
+
```
353
+
354
+
**Example Request:**
355
+
356
+
```bash
357
+
curl -X POST "http://localhost:8000/generate-sql" \
358
+
-H "Content-Type: application/json" \
359
+
-d '{"question": "Find all customers from Germany"}'
360
+
```
361
+
362
+
**Example Response:**
363
+
364
+
```json
365
+
{
366
+
"sql_query": "SELECT * FROM customers WHERE country = 'Germany';",
367
+
"sanitized_query": "SELECT * FROM customers WHERE country = 'Germany'",
368
+
"validate_query": "SELECT * FROM customers WHERE country = 'Germany'",
To start the development server with hot-reload, run:
@@ -298,8 +459,19 @@ To start the development server with hot-reload, run:
298
459
uvicorn src.main:app --reload
299
460
```
300
461
301
-
The API will be available at [http://localhost:8000](http://localhost:8000).
302
-
Access the automatically generated interactive documentation at [http://localhost:8000/docs](http://localhost:8000/docs) or the alternative ReDoc at [http://localhost:8000/redoc](http://localhost:8000/redoc).
462
+
The API will be available at [http://localhost:8000](http://localhost:8000).
0 commit comments