Reference Overview How to use Solace Code-Fixer API An API that fixes syntax errors: Built on Solanas blockchain
This API provides functionality for analyzing and automatically fixing code issues across various programs. By leveraging AI-based code analysis, it ensures efficient and accurate identification and resolution of errors.
Copy https://api.yourcodefixer.com/v1`
Analyzes the provided code and returns a list of detected issues.
Copy #### Endpoint
`POST /analyze`
#### Request
```json
{
"language": "javascript",
"code": "const x = 42 console.log(x)"
}
```
#### Response
```json
{
"issues": [
{
"line": 1,
"column": 16,
"message": "Missing semicolon.",
"type": "SyntaxError"
}
]
}
Automatically fixes issues in the provided code and returns the corrected version.
Copy #### Endpoint
`POST /fix`
#### Request
```json
{
"language": "javascript",
"code": "const x = 42 console.log(x)"
}
```
#### Response
```json
{
"fixedCode": "const x = 42; console.log(x);",
"changes": [
{
"line": 1,
"column": 16,
"change": "Added missing semicolon."
}
]
}
```
Provides optimized and cleaner alternatives for the provided code.
Copy #### Endpoint
`POST /suggest`
#### Request
```json
{
"language": "python",
"code": "x = [i for i in range(10) if i % 2 == 0]"
}
```
#### Response
```json
{
"suggestions": [
{
"optimizedCode": "x = list(range(0, 10, 2))",
"reason": "Simplified list comprehension with range step."
}
]
}
```
Retrieve a list of supported programming languages for code analysis and fixing.
Copy #### Endpoint
`GET /languages`
#### Response
```json
{
"languages": ["javascript", "python", "java", "c++", "solidity"]
}
```
---
## Error Handling
### Common Errors
- **400 Bad Request**: Missing required parameters.
- **401 Unauthorized**: Invalid API key.
- **500 Internal Server Error**: Server-side error.
#### Example Error Response
```json
{
"error": {
"code": 400,
"message": "Invalid JSON payload."
}
}
```
All requests require an API key. Include the following header in every request:
Copy Authorization: Bearer YOUR_API_KEY
```
---
## Example Usage (JavaScript)
```javascript
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const apiUrl = 'https://api.yourcodefixer.com/v1';
async function fixCode(language, code) {
try {
const response = await axios.post(
`${apiUrl}/fix`,
{ language, code },
{ headers: { Authorization: `Bearer ${apiKey}` } }
);
console.log('Fixed Code:', response.data.fixedCode);
} catch (error) {
console.error('Error:', error.response.data);
}
}
fixCode('javascript', 'const x = 42 console.log(x)');
```