57348b5ff56568fc194441e611564ac37c8f74eb
بسم الله الرحمن الرحيم
API Development with Monitoring
Objective:
Build a demo API (e.g., for a store, booking system, or any domain of your choice) with 6-7 documented endpoints, implement logging, monitor errors via a Bash script, and automate API requests.
Part 1: API Implementation
Requirements:
- Framework: Use any backend framework (e.g., Flask, Django, Express, Spring Boot).
- Endpoints:
- Include 6-7 RESTful endpoints (e.g.,
GET /items,POST /order,PUT /update). - Implement basic CRUD operations.
- Include 6-7 RESTful endpoints (e.g.,
- Documentation:
- Document all endpoints using Swagger/OpenAPI.
- Logging:
- Configure the API to log all output (requests, errors, etc.) to a file (e.g.,
api.log).
- Configure the API to log all output (requests, errors, etc.) to a file (e.g.,
Part 2: Log Monitoring with Bash
Requirements:
- Script: Write a Bash script (
monitor.sh) that:- Continuously reads the API log file (
api.log). - Detects HTTP error codes (e.g.,
4XX,5XX) or unusual patterns (e.g., "failed", "timeout").
- Continuously reads the API log file (
- Alerting:
- On error detection, the script must:
- Capture server metadata (IP, CPU/RAM usage, disk space) using commands like
df,free,top. - Send a JSON payload to a Ghaymah endpoint (URL provided later) via
curl. Example payload:{ "error": "500 Internal Server Error", "timestamp": "2023-11-15T12:00:00Z", "message": "db not connected", "server_metrics": { "ip": "192.168.1.1", "cpu_usage": "75%", "ram_available": "2GB", "disk_space": "50GB" } }
- Capture server metadata (IP, CPU/RAM usage, disk space) using commands like
- On error detection, the script must:
Part 3: API Automation Testing
Requirements:
- Script: Write a second Bash script (
test_api.sh) to automate API requests:- Send
GET,POST,PUT,DELETErequests to your endpoints. - Include payloads for
POST/PUT(e.g., adding a new item). - Log responses to a file (
test_results.log).
- Send
الوصف