File size: 1,574 Bytes
41e1749 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | // src/js/api.js
export async function analyzeText(text) {
const response = await fetch('/api/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
if (!response.ok) throw new Error('Analyze API error');
return await response.json();
}
export async function summarizeText(text, length = 2, full = true) {
const response = await fetch('/api/summarize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, length, full_text: full })
});
if (!response.ok) throw new Error('Summarize API error');
return await response.json();
}
export async function getSpelling(text) {
const response = await fetch('/api/spelling', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
if (!response.ok) throw new Error('Spelling API error');
return await response.json();
}
export async function getGrammar(text) {
const response = await fetch('/api/grammar', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
if (!response.ok) throw new Error('Grammar API error');
return await response.json();
}
export async function getPunctuation(text) {
const response = await fetch('/api/punctuation', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
if (!response.ok) throw new Error('Punctuation API error');
return await response.json();
}
|