API 사용 가이드

N/B 계산 데이터베이스 REST API 완벽 가이드

빠른 시작
Base URL
https://xn--9l4b4xi9r.com/api
인증

현재 인증이 필요하지 않습니다. 모든 API는 공개되어 있습니다.

Content-Type
Content-Type: application/json
API 엔드포인트 목록
메서드 엔드포인트 설명
POST /api/calculate 새로운 N/B 계산 실행 및 저장
POST /api/search 텍스트 또는 유니코드로 검색
GET /api/calculation/:id ID로 단일 조회 (조회수 증가)
GET /api/calculations 리스트 조회 (페이징)
GET /api/recent 최근 계산 결과 조회 (날짜순)
GET /api/most-viewed 조회수 많은 순 조회 NEW
GET /api/stats 통계 정보 조회
1. 계산 및 저장 API
POST /api/calculate
설명

텍스트 또는 숫자 배열을 N/B 계산하고 데이터베이스에 자동 저장합니다.

요청 본문 (텍스트)
const response = await fetch('/api/calculate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        input: "안녕하세요",
        bit: 999
    })
});
const result = await response.json();
console.log('ID:', result.calculation_id);
console.log('조회수:', result.view_count); // 0
$body = '{"input":"안녕하세요","bit":999}'
$result = Invoke-RestMethod `
    -Uri "https://xn--9l4b4xi9r.com/api/calculate" `
    -Method Post `
    -Body $body `
    -ContentType "application/json"

Write-Host "ID: $($result.calculation_id)"
Write-Host "조회수: $($result.view_count)"
curl -X POST https://xn--9l4b4xi9r.com/api/calculate \
  -H "Content-Type: application/json" \
  -d '{"input":"안녕하세요","bit":999}'
요청 파라미터
파라미터 타입 필수 설명
input string | array 계산할 텍스트 또는 숫자 배열
bit number 비트 값 (기본값: 999)
응답 예시
{
  "id": "a2ef74b40807f4c1",
  "timestamp": "2026-02-18T10:16:54.067Z",
  "type": "text",
  "input": "안녕하세요",
  "unicode": [50504, 45397, 54616, 49464, 50836],
  "bit": 999,
  "view_count": 0,
  "results": [{
    "calculation": 1,
    "nb_max": 12002.3230102511,
    "nb_min": 1.1290060488,
    "difference": 12001.1940042023
  }],
  "saved": true,
  "calculation_id": "a2ef74b40807f4c1"
}
2. 단일 조회 API (조회수 증가)
GET /api/calculation/:id
중요: 이 API를 호출할 때마다 view_count가 자동으로 증가합니다!
사용 예제
const id = "a2ef74b40807f4c1";
const response = await fetch(`/api/calculation/${id}`);
const data = await response.json();

console.log('조회수:', data.result.view_count);
console.log('마지막 조회:', data.result.last_viewed);
$id = "a2ef74b40807f4c1"
$r = Invoke-RestMethod -Uri "https://xn--9l4b4xi9r.com/api/calculation/$id"
Write-Host "조회수: $($r.result.view_count)"
응답 예시
{
  "result": {
    "id": "a2ef74b40807f4c1",
    "view_count": 6,
    "last_viewed": "2026-02-18T10:17:28.733Z",
    ...
  }
}
3. 검색 API
POST /api/search
텍스트로 검색
const response = await fetch('/api/search', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        text: "안녕하세요"
    })
});
const data = await response.json();
console.log('검색 결과:', data.results);
유니코드 배열로 검색
const response = await fetch('/api/search', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        unicode: [50504, 45397, 54616, 49464, 50836]
    })
});
const data = await response.json();
4. 리스트 조회 API
GET /api/calculations?limit=20
사용 예제
// 최신 20개 조회
const response = await fetch('/api/calculations?limit=20');
const data = await response.json();

data.results.forEach(item => {
    console.log(`ID: ${item.id}, 조회수: ${item.view_count}`);
});
쿼리 파라미터
파라미터 타입 기본값 설명
limit number 20 조회할 결과 개수 (10, 20, 50, 100)
5. 최근 계산 결과 조회 (날짜순)
GET /api/recent?limit=100
설명

가장 최근에 생성된 계산 결과를 날짜순으로 조회합니다. limit 파라미터로 개수를 지정할 수 있습니다.

파라미터
  • limit (선택): 조회할 개수 (기본값: 10, 최대 권장: 100)
사용 예제
// 최근 100개 조회
const response = await fetch('/api/recent?limit=100');
const data = await response.json();

console.log(`총 ${data.count}개 조회`);
data.results.forEach((item, index) => {
    console.log(`${index + 1}. ${item.id} - 생성: ${item.timestamp}`);
});
$response = Invoke-RestMethod -Uri "https://참소식.com/api/recent?limit=100" -Method Get
Write-Host "총 $($response.count)개 조회"
$response.results | Select-Object id, timestamp | Format-Table
curl "https://참소식.com/api/recent?limit=100"
응답 예시
{
  "success": true,
  "count": 100,
  "results": [
    {
      "id": "abc123...",
      "timestamp": "2026-02-18T10:30:00.000Z",
      "type": "text",
      "input": "안녕하세요",
      "view_count": 5,
      ...
    }
  ]
}
6. 조회수 많은 순 조회 NEW
GET /api/most-viewed?limit=100
설명

조회수가 가장 많은 계산 결과를 내림차순으로 조회합니다. 인기 있는 데이터를 확인할 때 유용합니다.

파라미터
  • limit (선택): 조회할 개수 (기본값: 10, 최대 권장: 100)
사용 예제
// 조회수 TOP 100
const response = await fetch('/api/most-viewed?limit=100');
const data = await response.json();

console.log(`총 ${data.count}개 조회`);
data.results.forEach((item, index) => {
    console.log(`${index + 1}위. ${item.id} - 조회수: ${item.view_count}회`);
});
$response = Invoke-RestMethod -Uri "https://참소식.com/api/most-viewed?limit=100" -Method Get
Write-Host "총 $($response.count)개 조회"
$response.results | Select-Object id, view_count, input | Format-Table
curl "https://참소식.com/api/most-viewed?limit=100"
응답 예시
{
  "success": true,
  "count": 100,
  "results": [
    {
      "id": "xyz789...",
      "timestamp": "2026-02-15T14:20:00.000Z",
      "type": "number",
      "input": [5, 9, 6, 8],
      "view_count": 125,
      "last_viewed": "2026-02-18T09:15:00.000Z",
      ...
    }
  ]
}
참고: 이 API는 모든 계산 파일을 읽어서 정렬하므로, 대량의 데이터가 있을 경우 응답 시간이 길어질 수 있습니다.
7. 통계 정보 API
GET /api/stats
사용 예제
const response = await fetch('/api/stats');
const stats = await response.json();
console.log('전체 계산 수:', stats.stats.total_calculations);
응답 예시
{
  "stats": {
    "total_calculations": 7,
    "total_max_results": 7,
    "total_min_results": 7
  }
}
실시간 API 테스트

브라우저 콘솔(F12)에서 바로 테스트해보세요:

// 1. 새 계산 생성
const calc = await fetch('/api/calculate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ input: "테스트", bit: 999 })
}).then(r => r.json());
console.log('생성된 ID:', calc.calculation_id);

// 2. ID로 조회 (조회수 증가)
const result = await fetch(`/api/calculation/${calc.calculation_id}`)
    .then(r => r.json());
console.log('조회수:', result.result.view_count);

// 3. 최근 100개 조회 (날짜순)
const recent = await fetch('/api/recent?limit=100').then(r => r.json());
console.log(`최근 ${recent.count}개:`, recent.results);

// 4. 조회수 TOP 100 (인기순)
const topViewed = await fetch('/api/most-viewed?limit=100').then(r => r.json());
console.log(`조회수 TOP ${topViewed.count}:`, topViewed.results);

// 5. 통계 확인
const stats = await fetch('/api/stats').then(r => r.json());
console.log('전체 계산 수:', stats.stats.total_calculations);

API 문의: 데이터베이스 페이지