|
| 1 | +# ArangoDB Service |
| 2 | + |
| 3 | +A small Python FastAPI service for basic ArangoDB operations. |
| 4 | + |
| 5 | +We publish this as the Docker image `arangodb/test-service` on Docker hub. |
| 6 | +It is regularly scanned for security vulnerabilities. |
| 7 | + |
| 8 | +## Requirements |
| 9 | + |
| 10 | +- Python 3.13+ |
| 11 | +- ArangoDB instance with JWT authentication |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +pip install -e . |
| 17 | +``` |
| 18 | + |
| 19 | +## Configuration |
| 20 | + |
| 21 | +Set the following environment variable: |
| 22 | + |
| 23 | +```bash |
| 24 | +export ARANGO_DEPLOYMENT_ENDPOINT="http://localhost:8529" |
| 25 | +``` |
| 26 | + |
| 27 | +## Running the Service |
| 28 | + |
| 29 | +```bash |
| 30 | +python main.py |
| 31 | +``` |
| 32 | + |
| 33 | +Or with uvicorn directly: |
| 34 | + |
| 35 | +```bash |
| 36 | +uvicorn main:app --host 0.0.0.0 --port 8000 |
| 37 | +``` |
| 38 | + |
| 39 | +## API Endpoints |
| 40 | + |
| 41 | +All endpoints require a JWT token in the `Authorization` header: |
| 42 | + |
| 43 | +``` |
| 44 | +Authorization: Bearer <your-jwt-token> |
| 45 | +``` |
| 46 | + |
| 47 | +### POST /write |
| 48 | + |
| 49 | +Creates the `test-service` database and in there the `test` collection |
| 50 | +(if these do not yet exist) and writes the request body as a document. |
| 51 | + |
| 52 | +**Example:** |
| 53 | +```bash |
| 54 | +curl -X POST http://localhost:8000/write \ |
| 55 | + -H "Authorization: Bearer YOUR_JWT_TOKEN" \ |
| 56 | + -H "Content-Type: application/json" \ |
| 57 | + -d '{"name": "example", "value": 42}' |
| 58 | +``` |
| 59 | + |
| 60 | +**Success Response (200):** |
| 61 | +```json |
| 62 | +{ |
| 63 | + "status": "success", |
| 64 | + "message": "Document written successfully", |
| 65 | + "document_key": "_key_value" |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +### GET /read |
| 70 | + |
| 71 | +Retrieves all documents from the `test` collection in the `test-service` |
| 72 | +database. |
| 73 | + |
| 74 | +**Example:** |
| 75 | +```bash |
| 76 | +curl -X GET http://localhost:8000/read \ |
| 77 | + -H "Authorization: Bearer YOUR_JWT_TOKEN" |
| 78 | +``` |
| 79 | + |
| 80 | +**Success Response (200):** |
| 81 | +```json |
| 82 | +{ |
| 83 | + "status": "success", |
| 84 | + "message": "Retrieved 1 document(s)", |
| 85 | + "documents": [ |
| 86 | + { |
| 87 | + "_key": "12345", |
| 88 | + "_id": "test/12345", |
| 89 | + "_rev": "_abc123", |
| 90 | + "name": "example", |
| 91 | + "value": 42 |
| 92 | + } |
| 93 | + ] |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### DELETE /delete |
| 98 | + |
| 99 | +Deletes the entire `test-service` database. |
| 100 | + |
| 101 | +**Example:** |
| 102 | +```bash |
| 103 | +curl -X DELETE http://localhost:8000/delete \ |
| 104 | + -H "Authorization: Bearer YOUR_JWT_TOKEN" |
| 105 | +``` |
| 106 | + |
| 107 | +**Success Response (200):** |
| 108 | +```json |
| 109 | +{ |
| 110 | + "status": "success", |
| 111 | + "message": "Collection 'test' deleted successfully" |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +## Error Handling |
| 116 | + |
| 117 | +All endpoints return HTTP 2xx status codes on success. Error responses include: |
| 118 | + |
| 119 | +- **401**: Missing Authorization header |
| 120 | +- **500**: Database errors or other server errors |
| 121 | + |
| 122 | +**Error Response Format:** |
| 123 | +```json |
| 124 | +{ |
| 125 | + "detail": "Descriptive error message" |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +## Health Check |
| 130 | + |
| 131 | +```bash |
| 132 | +curl http://localhost:8000/health |
| 133 | +``` |
| 134 | + |
| 135 | +Returns: |
| 136 | +```json |
| 137 | +{ |
| 138 | + "status": "healthy" |
| 139 | +} |
| 140 | +``` |
0 commit comments