|
| 1 | +# LeetCode & CodeChef API 🚀 |
| 2 | + |
| 3 | +A comprehensive REST API that provides access to both LeetCode and CodeChef data. Get user profiles, problem details, contest information, ratings, and more from both platforms! |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **LeetCode Data**: User profiles, badges, solved problems, contest history, submissions |
| 8 | +- **CodeChef Data**: User profiles, ratings, rankings, contest statistics (returns 0 if no contests) |
| 9 | +- **Problem Data**: Daily questions, problem lists with filtering, detailed problem info |
| 10 | +- **Discussion Data**: Trending discussions, topics, and comments |
| 11 | +- **Advanced Features**: Rate limiting, error handling, CORS support, compression |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +# Clone the repository |
| 19 | +git clone <your-repo-url> |
| 20 | +cd leetcode-api |
| 21 | + |
| 22 | +# Install dependencies |
| 23 | +npm install |
| 24 | + |
| 25 | +# Start the server |
| 26 | +npm start |
| 27 | + |
| 28 | +# For development with auto-reload |
| 29 | +npm run dev |
| 30 | +``` |
| 31 | + |
| 32 | +### Usage |
| 33 | + |
| 34 | +The API will be available at `http://localhost:3000` |
| 35 | + |
| 36 | +## API Endpoints |
| 37 | + |
| 38 | +### 👤 User Endpoints |
| 39 | + |
| 40 | +| Endpoint | Description | Example | |
| 41 | +|----------|-------------|---------| |
| 42 | +| `/:username` | Get user profile details | `/john_doe` | |
| 43 | +| `/:username/badges` | Get user badges | `/john_doe/badges` | |
| 44 | +| `/:username/solved` | Get solved problems statistics | `/john_doe/solved` | |
| 45 | +| `/:username/contest` | Get contest participation details | `/john_doe/contest` | |
| 46 | +| `/:username/contest/history` | Get contest history | `/john_doe/contest/history` | |
| 47 | +| `/:username/submission` | Get recent submissions (last 20) | `/john_doe/submission` | |
| 48 | +| `/:username/submission?limit=10` | Get limited submissions | `/john_doe/submission?limit=10` | |
| 49 | +| `/:username/acSubmission` | Get accepted submissions | `/john_doe/acSubmission` | |
| 50 | +| `/:username/acSubmission?limit=7` | Get limited accepted submissions | `/john_doe/acSubmission?limit=7` | |
| 51 | +| `/:username/calendar` | Get submission calendar | `/john_doe/calendar` | |
| 52 | + |
| 53 | +### 😀 New User Endpoints |
| 54 | + |
| 55 | +| Endpoint | Description | Example | |
| 56 | +|----------|-------------|---------| |
| 57 | +| `/userProfile/:username` | Get full profile in one call | `/userProfile/john_doe` | |
| 58 | +| `/userProfileCalendar?username=name&year=2024` | Get calendar with year | `/userProfileCalendar?username=john_doe&year=2024` | |
| 59 | +| `/languageStats?username=name` | Get language statistics | `/languageStats?username=john_doe` | |
| 60 | +| `/userProfileUserQuestionProgressV2/:userSlug` | Get question progress | `/userProfileUserQuestionProgressV2/john_doe` | |
| 61 | +| `/skillStats/:username` | Get skill statistics | `/skillStats/john_doe` | |
| 62 | +| `/userContestRankingInfo/:username` | Get contest ranking | `/userContestRankingInfo/john_doe` | |
| 63 | + |
| 64 | +### ❓ Problem Endpoints |
| 65 | + |
| 66 | +| Endpoint | Description | Example | |
| 67 | +|----------|-------------|---------| |
| 68 | +| `/daily` | Get daily challenge question | `/daily` | |
| 69 | +| `/dailyQuestion` | Get raw daily question data | `/dailyQuestion` | |
| 70 | +| `/select?titleSlug=question-slug` | Get specific question details | `/select?titleSlug=two-sum` | |
| 71 | +| `/problems` | Get problems list (20 by default) | `/problems` | |
| 72 | +| `/problems?limit=10` | Get limited number of problems | `/problems?limit=10` | |
| 73 | +| `/problems?tags=array+string` | Filter problems by tags | `/problems?tags=array+string` | |
| 74 | +| `/problems?difficulty=EASY` | Filter by difficulty (EASY/MEDIUM/HARD) | `/problems?difficulty=EASY` | |
| 75 | +| `/problems?skip=20` | Skip first N problems | `/problems?skip=20` | |
| 76 | +| `/problems?tags=array&limit=10&skip=5` | Combined filters | `/problems?tags=array&limit=10&skip=5` | |
| 77 | + |
| 78 | +### 💬 Discussion Endpoints |
| 79 | + |
| 80 | +| Endpoint | Description | Example | |
| 81 | +|----------|-------------|---------| |
| 82 | +| `/trendingDiscuss?first=20` | Get trending discussions | `/trendingDiscuss?first=10` | |
| 83 | +| `/discussTopic/:topicId` | Get discussion topic | `/discussTopic/12345` | |
| 84 | +| `/discussComments/:topicId` | Get discussion comments | `/discussComments/12345` | |
| 85 | + |
| 86 | +## Response Format |
| 87 | + |
| 88 | +All endpoints return data in a consistent format: |
| 89 | + |
| 90 | +```json |
| 91 | +{ |
| 92 | + "success": true, |
| 93 | + "message": "Data retrieved successfully", |
| 94 | + "data": { ... }, |
| 95 | + "timestamp": "2024-01-01T12:00:00.000Z" |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +### Error Response |
| 100 | + |
| 101 | +```json |
| 102 | +{ |
| 103 | + "success": false, |
| 104 | + "message": "Error description", |
| 105 | + "timestamp": "2024-01-01T12:00:00.000Z" |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +## Query Parameters |
| 110 | + |
| 111 | +### Problems Endpoint |
| 112 | + |
| 113 | +- `limit`: Number of problems to return (max 100, default 20) |
| 114 | +- `skip`: Number of problems to skip (default 0) |
| 115 | +- `tags`: Filter by tags (use + to separate multiple tags) |
| 116 | +- `difficulty`: Filter by difficulty (EASY, MEDIUM, HARD) |
| 117 | + |
| 118 | +### Example Queries |
| 119 | + |
| 120 | +```bash |
| 121 | +# Get user profile |
| 122 | +curl http://localhost:3000/john_doe |
| 123 | + |
| 124 | +# Get daily question |
| 125 | +curl http://localhost:3000/daily |
| 126 | + |
| 127 | +# Get 10 easy array problems |
| 128 | +curl "http://localhost:3000/problems?difficulty=EASY&tags=array&limit=10" |
| 129 | + |
| 130 | +# Get trending discussions |
| 131 | +curl "http://localhost:3000/trendingDiscuss?first=5" |
| 132 | +``` |
| 133 | + |
| 134 | +## Rate Limiting |
| 135 | + |
| 136 | +- 100 requests per 15 minutes per IP address |
| 137 | +- Rate limit headers included in responses: |
| 138 | + - `X-RateLimit-Limit`: Request limit |
| 139 | + - `X-RateLimit-Remaining`: Remaining requests |
| 140 | + - `X-RateLimit-Reset`: Reset time |
| 141 | + |
| 142 | +## Environment Variables |
| 143 | + |
| 144 | +Create a `.env` file for configuration: |
| 145 | + |
| 146 | +```env |
| 147 | +PORT=3000 |
| 148 | +NODE_ENV=development |
| 149 | +``` |
| 150 | + |
| 151 | +## Error Handling |
| 152 | + |
| 153 | +The API includes comprehensive error handling for: |
| 154 | +- Invalid usernames |
| 155 | +- Non-existent users |
| 156 | +- Malformed requests |
| 157 | +- Rate limiting |
| 158 | +- Network errors |
| 159 | +- GraphQL errors |
| 160 | + |
| 161 | +## Technologies Used |
| 162 | + |
| 163 | +- **Node.js** - Runtime environment |
| 164 | +- **Express.js** - Web framework |
| 165 | +- **Axios** - HTTP client for GraphQL requests |
| 166 | +- **CORS** - Cross-origin resource sharing |
| 167 | +- **Helmet** - Security headers |
| 168 | +- **Compression** - Response compression |
| 169 | + |
| 170 | +## Contributing |
| 171 | + |
| 172 | +1. Fork the repository |
| 173 | +2. Create a feature branch |
| 174 | +3. Make your changes |
| 175 | +4. Add tests if applicable |
| 176 | +5. Submit a pull request |
| 177 | + |
| 178 | +## License |
| 179 | + |
| 180 | +MIT License - see LICENSE file for details |
| 181 | + |
| 182 | +## Support |
| 183 | + |
| 184 | +For issues and questions: |
| 185 | +- Create an issue on GitHub |
| 186 | +- Check the API documentation at `http://localhost:3000/` |
| 187 | +- Verify your requests match the expected format |
| 188 | + |
| 189 | +## Changelog |
| 190 | + |
| 191 | +### v1.0.0 |
| 192 | +- Initial release with all LeetCode API endpoints |
| 193 | +- User profile and statistics |
| 194 | +- Problem data and daily questions |
| 195 | +- Discussion and trending topics |
| 196 | +- Rate limiting and error handling |
0 commit comments