![image](https://private-user-images.githubusercontent.com/93156666/384594180-72c14348-e382-4fc9-a908-5ed577e39ed4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ1OTQxODAtNzJjMTQzNDgtZTM4Mi00ZmM5LWE5MDgtNWVkNTc3ZTM5ZWQ0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZjN2VmNDg0MDEyZDg2ZTNlY2RhNTdiMWNkMDdkODJjMmNmMzA0YTAyOTM0NjI1MmU4YjJhYjI1ZDEzZGJlMzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6rlubRAsQa6yrZWWCA0Th_Cy2P7waay_4jf1LXazRF0)
This API playground serves as a platform for users to test their API clients during a workshop. It is built using Python with the FastAPI library. The host features a simple yet robust frontend that provides the following functionalities:
- Feature: Allow users to generate their own authentication tokens.
- Frontend: A form where users can input their name.
- Backend: Generate and return a unique token for the user.
![image](https://private-user-images.githubusercontent.com/93156666/384652474-8d41c396-ce49-4165-a58f-5b7ac3edadf9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0NzQtOGQ0MWMzOTYtY2U0OS00MTY1LWE1OGYtNWI3YWMzZWRhZGY5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE4ZjBhNzRlOWRlODlmNmIwOGJjM2E1MjU2YmNlNTE3NDk3ZjJiZDg4NjI4OTA1MmMwZTdhZTc0YzZlNTFhNGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.-FRpMjOoZdzwvo_-E9cxr_6JBH6Ae0dreH_J3C7YSM4)
- Feature: Stream incoming API requests to the browser in real-time.
- Frontend: A live feed that displays incoming requests as they are received.
- Backend: Capture and stream incoming requests to the frontend using WebSockets.
![image](https://private-user-images.githubusercontent.com/93156666/384652385-c80fe9df-c918-4889-ac33-988d6d3a453f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTIzODUtYzgwZmU5ZGYtYzkxOC00ODg5LWFjMzMtOTg4ZDZkM2E0NTNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNkNzk2ODEzODc0MjM4NDkxOTY5ODRlMmU1MjNhYTU4ODIwNTFjZTFiOWY4OTcwODM0OTUxNjZkOTBkNzFmODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3C-UQNp3hf4h1ZtueqTQumU4_A6rxPMGWvlKKa9OiAc)
- Feature: Allow users to call their own API hosts.
- Frontend: An input field for the endpoint URI, request type (GET/PUT/PATCH), content type, and request body (for PUT/PATCH).
- Backend: Send the specified request to the provided endpoint and display the response.
![image](https://private-user-images.githubusercontent.com/93156666/384652417-8fdc1080-d6bf-4788-9cd8-7ced75378ccd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MTctOGZkYzEwODAtZDZiZi00Nzg4LTljZDgtN2NlZDc1Mzc4Y2NkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQyZjFkOTMwMzMwNzAyY2ZiODU3YjFiOWEyZDI4OGMxMDc2MTI5MjdhOWU1YWExZjc5ZjdmYmFiZjc0ZTI0NzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GdZHRZj3U1SGBdvipd1zYpJAnVCCGupjiL7D9Z1Wbhg)
- Feature: Manage employee and department sample data.
- Frontend: Tables to display employee and department data with pagination.
- Backend: Endpoints to create, read, update, and delete employee and department records.
![image](https://private-user-images.githubusercontent.com/93156666/384652427-ab87d890-8964-4eac-bb93-e0d567bfdf91.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MjctYWI4N2Q4OTAtODk2NC00ZWFjLWJiOTMtZTBkNTY3YmZkZjkxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFiYjMyYTE2MGMwMmM2YWY1ZjkzZjNhMTEwM2JiNTE2ODliYTBmOWYxZGRiNDc3MzIwMjVjMGYzYTM1ZTc2NzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Jmi176ATu2xIkfAZAbYDQvPtMVR6dOeyF6Qqra8p0Ks)
- Feature: Admin functionalities to reset employee, department, and token data.
- Frontend: Admin panel with password protection.
- Backend: Endpoints to reset employee, department, and token data.
![image](https://private-user-images.githubusercontent.com/93156666/384652436-34f8056c-036a-4fff-b8f0-31d1890f2822.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjYxNjIsIm5iZiI6MTczOTU2NTg2MiwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MzYtMzRmODA1NmMtMDM2YS00ZmZmLWI4ZjAtMzFkMTg5MGYyODIyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwNDQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ0NzYyNjQwYTE0ZjcwM2JhMGMwNDYxMjRjYWU1ZGM5NGEzYjA4MDYxMWUyMDU1NWViMTdiYzNkNmU1NGY0ZWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.rj1myt3Jt9jKFItFw80Vlbad7Mcs-5sCpbeRoE99lI0)
- Python Version: 3.9+
- Libraries: FastAPI, SQLAlchemy, Jinja2, Uvicorn, more (see:
requirements.txt
) - Platform: Designed on macOS for IBM i. Should run anywhere you can install the required python packages. Database is self-contained.
- GET /requests: Serve the requests page that displays incoming requests in real-time.
- Response: HTML page with a live feed of incoming requests.
- /ws: WebSocket endpoint to stream incoming requests to the frontend in real-time.
- /echo: Handle all HTTP methods and echo back the request details.
- Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, CONNECT, TRACE
- Request Headers:
- Authorization: Bearer token (optional)
- Request Body: Any valid JSON or text
- Response:
{ "uri": "string", "method": "string", "body": "string" }
- GET /employees: Get a paginated list of employees.
- Response:
{ "employees": [], "totalPages": "integer", "totalRows": "integer" }
- Response:
- PUT /employees: Create a new employee.
- Request Body:
{ "first": "string", "last": "string", "job": "string", "workdept": "string", "salary": "number" }
- Response:
{ "id": "string", "first": "string", "last": "string", "job": "string", "workdept": "string", "salary": "number" }
- Request Body:
- GET /departments: Get a paginated list of departments.
- Response:
{ "departments": [], "totalPages": "integer", "totalRows": "integer" }
- Response:
- PUT /departments: Create a new department.
- Request Body:
{ "id": "string", "name": "string", "manager": "string", "location": "string" }
- Response:
{ "id": "string", "name": "string", "manager": "string", "location": "string" }
- Request Body:
- /{path:path}: Handle unhandled methods and return appropriate HTTP error messages to websocket stream.
- Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
- Response: HTTP 405 Method Not Allowed or HTTP 404 Not Found
-
Clone the repository:
git clone https://github.com/wright4i/api-playground.git
-
Create a virtual environment:
python3 -m venv --system-site-packages api-playground
-
Activate the virtual environment:
- On PASE (IBM i):
. api-playground/bin/activate
- On macOS/Linux:
source api-playground/bin/activate
- On Windows:
api-playground\Scripts\activate
- On PASE (IBM i):
-
Change directory:
cd api-playground
-
Install the required packages:
pip install -r requirements.txt
-
Copy the example environment file and set up the environment variables:
cp .env.example .env
Edit the
.env
file to configure the necessary variables. -
Run the application:
uvicorn app.main:app --reload --host 0.0.0.0 --port 10500
api-playground/
├── app/
│ ├── main.py
│ ├── templates.py
│ ├── utils.py
│ ├── connections/
│ │ ├── base.py
│ │ └── sqlite.py
│ ├── models/
│ │ ├── department.py
│ │ ├── employee.py
│ │ └── token.py
│ └── routers/
│ ├── department.py
│ ├── echo.py
│ ├── employee.py
│ ├── reverse.py
│ ├── token.py
│ └── websocket.py
├── templates/
│ ├── index.html
│ ├── auth_token_modal.html
│ ├── admin_panel_modal.html
│ ├── send_tab.html
│ ├── receive_tab.html
│ ├── employee_tab.html
│ └── department_tab.html
├── static/
│ ├── css/
│ │ ├── dracula.css
│ │ └── styles.css
│ └── js/
│ ├── admin_panel_modal.js
│ ├── auth_token_modal.js
│ ├── department_tab.js
│ ├── employee_tab.js
│ ├── index.js
│ ├── receive_tab.js
│ └── send_tab.js
├── requirements.txt
├── playground.yml
└── README.md