LeetCode Stats Card API Documentation
Introduction
Welcome to the LeetCode Stats Card API documentation. This API allows you to generate and embed customizable stat cards for LeetCode profiles.
Endpoints
GET /api/cardgen ▼
Generates a LeetCode stats card image.
Parameters:
- username (required): LeetCode username
- theme (required): Card theme (e.g., dark, light)
- font (required): Font style for the card
- extension (optional): File extension
- site (optional): Site identifier
Returns: The stats card image data
GET /api/cardgenDetail ▼
Generates embed code for the LeetCode stats card.
Parameters:
- username (required): LeetCode username
- theme (required): Card theme (e.g., dark, light)
- font (required): Font style for the card
- extension (optional): File extension
- site (optional): Site identifier
Returns: JSON object containing embedHtml and markdown
GET /api/preview ▼
Provides a preview of the stats card.
Parameters:
- username (required): LeetCode username
- theme (required): Card theme (e.g., dark, light)
- font (required): Font style for the card
- extension (optional): File extension
- site (optional): Site identifier
Returns: The source of the embed code
Examples
Generating a card image:
fetch('/api/cardgen?username=devagn_maniya&theme=dark&font=changa')
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Getting embed code:
fetch('/api/cardgenDetail?username=devagn_maniya&theme=dark&font=changa')
.then(response => response.json())
.then(data => {
console.log('Embed HTML:', data.embedHtml);
console.log('Markdown:', data.markdown);
})
.catch(error => console.error('Error:', error));
Getting a preview:
fetch('/api/preview?username=devagn_maniya&theme=dark&font=changa')
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Error Handling
If required parameters are missing or an error occurs, the API will return a JSON response with an error message:
{
"error": "Username, theme, and font are required."
}