An interactive terminal application for making API requests using the Ky library. This CLI tool allows you to perform HTTP methods like GET
, POST
, PUT
, PATCH
, DELETE
, and more, directly from your terminal.
- Interactive terminal interface.
- Support for common HTTP methods:
GET
POST
PUT
PATCH
DELETE
HEAD
- Command to clear the terminal (
clear
). - Easy-to-use help menu (
help
). - Configurable API base URL with timeouts.
- Extensible for additional commands.
git clone https://github.com/beesou777/ky-fetch-terminal.git
cd ky-fetch-terminal
npm install
npm run start
You’ll see the welcome message:
Welcome to the KY API Terminal!
Type "help" for a list of available commands.
KY-CLI>
Command | Description |
---|---|
get <endpoint> |
Fetch data from the server (e.g., get todos/1 ). |
post <endpoint> <body> |
Create a new resource. body should be a JSON string (e.g., post posts '{"title":"foo"} ). |
put <endpoint> <body> |
Replace a resource. body should be a JSON string (e.g., put posts/1 '{"userId":1,"title":"bar"} ). |
patch <endpoint> <body> |
Partially update a resource. body should be a JSON string (e.g., patch posts/1 '{"title":"baz"}' ). |
delete <endpoint> |
Delete a resource from the server (e.g., delete posts/1 ). |
head <endpoint> |
Fetch only headers and status of a resource (e.g., head todos/1 ). |
clear |
Clear the terminal screen. |
help |
Display a help menu with all available commands. |
exit |
Exit the terminal. |
KY-CLI> get todos/1
Output:
GET Response: {
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
KY-CLI> post posts {"title":"foo","body":"bar","userId":1}
Output:
POST Response: {
"id": 101,
"title": "foo",
"body": "bar",
"userId": 1
}
KY-CLI> put posts/1 {"title":"foo","body":"bar","userId":1}
Output:
PUT Response: {
"title": "foo",
"body": "bar",
"userId": 1,
"id": 1
}
KY-CLI> clear
Output:
Screen cleared! Type "help" for available commands.
You can modify the base URL, timeout, or headers in the index.js
file:
const apiClient = ky.create({
prefixUrl: 'https://jsonplaceholder.typicode.com',
timeout: 5000,
headers: {
'Content-Type': 'application/json',
},
});
prefixUrl
: The base URL for all API requests.timeout
: The maximum time to wait for a response (in milliseconds).headers
: Default headers sent with every request.
We welcome contributions to improve this tool! Follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b feature-name
- Make your changes and commit them:
git commit -m "Add your message here"
- Push to your fork:
git push origin feature-name
- Open a pull request.