![image](https://private-user-images.githubusercontent.com/93156666/384594180-72c14348-e382-4fc9-a908-5ed577e39ed4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ1OTQxODAtNzJjMTQzNDgtZTM4Mi00ZmM5LWE5MDgtNWVkNTc3ZTM5ZWQ0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyODQxY2FiMTQwZWQ3MTc1OGY5ODViNzg3MDY5NmI4MGViN2YzNzM3NDJmMmY3ZWM4NmFiN2NiNDU5OTFmZDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.wcd_OvLQq5Jg9joL1mQNt541vm56chLoBVBr6DLUMaI)
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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0NzQtOGQ0MWMzOTYtY2U0OS00MTY1LWE1OGYtNWI3YWMzZWRhZGY5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE0YjRjNTc3YzBlMzNhZTYxY2ZhYTMxZGNhNTA0ZWU2ZTQ2Y2JjZWE5YTM0NjhkY2YyYTFjN2Y4MmVjZGYxYjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Yf8G_oIJEackKO8mWAtvNa_I_GdrANoLbMsla4akLeA)
- 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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTIzODUtYzgwZmU5ZGYtYzkxOC00ODg5LWFjMzMtOTg4ZDZkM2E0NTNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwYzM0ZDRmNjQxMTA1NjdmMzAyODhkNjM4MGIyNDU1Y2YxOWRiZTNjYmUwMTdkMmM2Nzk0MTYyMzFlNzg4YzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.dYAADXVPI-gX5vYuSD60IMzEnoP4YKr2YWTSD7XlyM8)
- 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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MTctOGZkYzEwODAtZDZiZi00Nzg4LTljZDgtN2NlZDc1Mzc4Y2NkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg5NGY3OThiN2U3ZGMxYTMzZGM4YTI1NTUxODQ0NzcyODRmYjRhNWQzZmMzYWUzMjllNmEyMzJhYmFmNGNkZmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.t0iz8j1Etxn4jgAC2-N1V1innHPVmUVhH-xO5vbNLus)
- 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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MjctYWI4N2Q4OTAtODk2NC00ZWFjLWJiOTMtZTBkNTY3YmZkZjkxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZkM2M0MWI1YjIxOGQwMGNkMTFmY2Q1ZGQ3NGE0MTdkMTdhMTY4OWY1MzMzMjAzODYyZmIxZTg5YmRjMWYwNDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.u94udAGCU-1LC091kkZeiJLBwTHoe7CsxuKQG37J6Rg)
- 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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDkyNzksIm5iZiI6MTczOTUwODk3OSwicGF0aCI6Ii85MzE1NjY2Ni8zODQ2NTI0MzYtMzRmODA1NmMtMDM2YS00ZmZmLWI4ZjAtMzFkMTg5MGYyODIyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDA0NTYxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg4NTdkYWRkZjNjZjRmNzdhNjE5NWQzYzk4YmE0ZGE1NzIwZTBiNzJiMmNhZWU4OWQ4MTZhYzFlYWZjMjQ5ZjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.SF43RDZiBT2HQrROz8St6CiWdynEP8xJQ4vzAvN_FOM)
- 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