|
1 |
| -# ChatGPT-API |
2 |
| -fast and free ChatGPT API for node.js |
| 1 | +# ChatGPT API for Node.js |
| 2 | + |
| 3 | +This repository contains a simple and modern API for interacting with ChatGPT using Node.js. It's fast, free, and easy to use. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +First, clone the repository: |
| 8 | + |
| 9 | +```bash |
| 10 | +git clone https://github.com/ReactMVC/ChatGPT-API.git |
| 11 | +``` |
| 12 | + |
| 13 | +Navigate into the project directory: |
| 14 | + |
| 15 | +```bash |
| 16 | +cd ChatGPT-API |
| 17 | +``` |
| 18 | + |
| 19 | +Install the necessary dependencies: |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install |
| 23 | +``` |
| 24 | + |
| 25 | +Start the server: |
| 26 | + |
| 27 | +```bash |
| 28 | +node index.js |
| 29 | +``` |
| 30 | +The server will start running on port 3000. |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +The API provides two endpoints, both of which accept a `text` parameter: |
| 35 | + |
| 36 | +- GET `/` |
| 37 | +- POST `/` |
| 38 | + |
| 39 | +## Fetch |
| 40 | + |
| 41 | +##### GET |
| 42 | + |
| 43 | +```javascript |
| 44 | +fetch('http://localhost:3000/?text=Hello', { |
| 45 | + method: 'GET', |
| 46 | +}) |
| 47 | +.then(response => response.json()) |
| 48 | +.then(data => console.log(data)); |
| 49 | +``` |
| 50 | + |
| 51 | +##### POST |
| 52 | + |
| 53 | +```javascript |
| 54 | +fetch('http://localhost:3000/', { |
| 55 | + method: 'POST', |
| 56 | + headers: { |
| 57 | + 'Content-Type': 'application/json; charset=utf-8', |
| 58 | + }, |
| 59 | + body: JSON.stringify({ text: 'Hello' }), |
| 60 | +}) |
| 61 | +.then(response => response.json()) |
| 62 | +.then(data => console.log(data)); |
| 63 | +``` |
| 64 | + |
| 65 | +## Axios |
| 66 | + |
| 67 | +##### GET |
| 68 | + |
| 69 | +```javascript |
| 70 | +axios.get('http://localhost:3000/', { |
| 71 | + params: { |
| 72 | + text: 'Hello', |
| 73 | + }, |
| 74 | +}) |
| 75 | +.then(response => console.log(response.data)); |
| 76 | +``` |
| 77 | + |
| 78 | +##### POST |
| 79 | + |
| 80 | +```javascript |
| 81 | +axios.post('http://localhost:3000/', { |
| 82 | + text: 'Hello', |
| 83 | +}, { |
| 84 | + headers: { |
| 85 | + 'Content-Type': 'application/json; charset=utf-8', |
| 86 | + }, |
| 87 | +}) |
| 88 | +.then(response => console.log(response.data)); |
| 89 | +``` |
| 90 | + |
| 91 | +## Contact |
| 92 | + |
| 93 | +For any issues, suggestions, or general feedback, please contact: |
| 94 | + |
| 95 | +- Name: Hossein Pira |
| 96 | +- Email: h3dev.pira@gmail.com |
| 97 | +- Telegram: [@h3dev](https://t.me/h3dev) |
| 98 | + |
| 99 | +Enjoy using the ChatGPT API! |
0 commit comments