Jump Into Our API Testing Adventure – $250 Prize + Swag for first 15 submissions

I wanted to explore how far I could go using external npm packages and ended up creating a little article/text analyzer that does:

  • :globe_showing_europe_africa: Language detection
  • :brain: Sentiment analysis
  • :memo: Article summarization
  • :bar_chart: Visual display using the Postman visualizer

:wrench: What I Used

Here are the packages I pulled in and how I used each:

1. franc – Language Detection

Used to detect the language of the article content.

const francFunc = pm.require('npm:[email protected]');
const lang = francFunc.franc(body);

2. sentiment – Sentiment Analysis

Analyzes the article text and gives a sentiment score (positive, neutral, negative).

const Sentiment = pm.require('npm:[email protected]');
const sentiment = new Sentiment();
const sentimentResult = sentiment.analyze(body);

3. node-summary – Summarization

Generates a short summary from the article title + body.

const summary = pm.require('npm:[email protected]');
summary.summarize(title, body, callback);

:technologist: Full code

const Sentiment = pm.require('npm:[email protected]');
const francFunc = pm.require('npm:[email protected]');
const summary = pm.require('npm:[email protected]');

const sentiment = new Sentiment();

// Extract article data
const body = pm.response.json().data.content || '';
const title = pm.response.json()?.data.title || "Untitled Article";

console.log(`🔍 Analyzing: "${title}"`);
console.log(`📊 Content length: ${body.length} characters`);

// --- Language Detection ---
const lang = francFunc.franc(body);
const langName = getLangName(lang);
pm.environment.set("article_lang", lang);
console.log(`🌐 Language detected: ${langName} (${lang})`);

// --- Sentiment Analysis ---
const sentimentResult = sentiment.analyze(body);
const sentimentEmoji = getSentimentEmoji(sentimentResult.score);
pm.environment.set("article_sentiment", sentimentResult.score);
console.log(`${sentimentEmoji} Sentiment score: ${sentimentResult.score}`);

// --- Summarization ---
summary.summarize(title, body, (err, sum) => {
    if (err) {
        console.error("❌ Summarization failed:", err.message);
        sum = "⚠️ Unable to generate summary - content might be too short or complex.";
    } else {
        console.log(`✅ Summary generated (${sum.length} chars)`);
    }
    
    pm.environment.set("article_summary", sum);
    
    // --- Visualizer ---
    pm.visualizer.set(`
    <html>
      <head>
        <style>
          * { margin: 0; padding: 0; box-sizing: border-box; }
          
          body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            min-height: 100vh;
            padding: 20px;
          }
          
          .container {
            max-width: 800px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            backdrop-filter: blur(10px);
          }
          
          .header {
            background: linear-gradient(45deg, #4facfe 0%, #00f2fe 100%);
            color: white;
            padding: 30px;
            text-align: center;
          }
          
          .header h1 {
            font-size: 28px;
            margin-bottom: 10px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.2);
          }
          
          .content {
            padding: 30px;
          }
          
          .metric {
            margin-bottom: 25px;
            padding: 20px;
            border-radius: 15px;
            background: white;
            border-left: 4px solid;
            box-shadow: 0 4px 15px rgba(0,0,0,0.05);
            transition: transform 0.2s ease;
          }
          
          .metric:hover {
            transform: translateY(-2px);
          }
          
          .metric.summary { border-color: #3498db; }
          .metric.language { border-color: #9b59b6; }
          .metric.sentiment { border-color: {{sentimentColor}}; }
          
          .metric-header {
            display: flex;
            align-items: center;
            margin-bottom: 12px;
          }
          
          .metric-icon {
            font-size: 24px;
            margin-right: 12px;
          }
          
          .metric-title {
            font-size: 18px;
            font-weight: 600;
            color: #2c3e50;
          }
          
          .metric-value {
            font-size: 16px;
            line-height: 1.6;
            color: #34495e;
          }
          
          .score {
            font-size: 24px;
            font-weight: bold;
            color: {{sentimentColor}};
          }
          
          .badge {
            display: inline-block;
            background: {{sentimentBg}};
            color: {{sentimentColor}};
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
            margin-left: 10px;
          }
          
        </style>
      </head>
      <body>
        <div class="container">
          <div class="header">
            <h1>📰 Your Article Analysis</h1>
          </div>
          
          <div class="content">
            <div class="metric summary">
              <div class="metric-header">
                <span class="metric-icon">📝</span>
                <span class="metric-title">Summary</span>
              </div>
              <div class="metric-value">{{summary}}</div>
            </div>
            
            <div class="metric language">
              <div class="metric-header">
                <span class="metric-icon">🌐</span>
                <span class="metric-title">Language</span>
              </div>
              <div class="metric-value">
                <strong>{{langName}}</strong> ({{lang}})
              </div>
            </div>
            
            <div class="metric sentiment">
              <div class="metric-header">
                <span class="metric-icon">{{sentimentEmoji}}</span>
                <span class="metric-title">Sentiment Analysis</span>
              </div>
              <div class="metric-value">
                <span class="score">{{sentiment}}</span>
                <span class="badge">{{sentimentLabel}}</span>
              </div>
            </div>
          </div>
        </div>
      </body>
    </html>
    `, {
        summary: sum,
        lang: lang,
        langName: langName,
        sentiment: sentimentResult.score,
        sentimentEmoji: sentimentEmoji,
        sentimentLabel: getSentimentLabel(sentimentResult.score),
        sentimentColor: getSentimentColor(sentimentResult.score),
        sentimentBg: getSentimentBg(sentimentResult.score)
    });
});

// --- Functions ---
function getLangName(code) {
    const languages = {
        'eng': 'English', 'spa': 'Spanish', 'fra': 'French', 'deu': 'German',
        'ita': 'Italian', 'por': 'Portuguese', 'rus': 'Russian', 'jpn': 'Japanese',
        'kor': 'Korean', 'cmn': 'Chinese', 'ara': 'Arabic', 'hin': 'Hindi'
    };
    return languages[code] || 'Unknown';
}

function getSentimentEmoji(score) {
    if (score > 2) return '😍';
    if (score > 0) return '😊';
    if (score === 0) return '😐';
    if (score > -2) return '😕';
    return '😤';
}

function getSentimentLabel(score) {
    if (score > 2) return 'Very Positive';
    if (score > 0) return 'Positive';
    if (score === 0) return 'Neutral';
    if (score > -2) return 'Negative';
    return 'Very Negative';
}

function getSentimentColor(score) {
    if (score > 0) return '#27ae60';
    if (score === 0) return '#f39c12';
    return '#e74c3c';
}

function getSentimentBg(score) {
    if (score > 0) return '#d5f4e6';
    if (score === 0) return '#fef9e7';
    return '#fadbd8';
}


pm.test("🎯 Article has substantial content", function () {
    pm.expect(body.length).to.be.above(100);
    console.log(`✅ Content check passed: ${body.length} characters`);
});

pm.test("📖 Summary generation successful", function () {
    const summary = pm.environment.get("article_summary");
    pm.expect(summary).to.be.a("string");
    pm.expect(summary.length).to.be.above(10);
    console.log("✅ Summary check passed");
});

pm.test("🌍 Language detection completed", function () {
    const detectedLang = pm.environment.get("article_lang");
    pm.expect(detectedLang).to.be.a("string");
    pm.expect(detectedLang.length).to.equal(3);
    console.log(`✅ Language detection passed: ${detectedLang}`);
});

pm.test("🧠 Sentiment analysis completed", function () {
    const sentiment = pm.environment.get("article_sentiment");
    pm.expect(sentiment).to.be.a("number");
    console.log(`✅ Sentiment analysis passed: ${sentiment}`);
});

console.log("🎉 Analysis complete! Check the visualizer for beautiful results.");

:light_bulb: How It Works

  • The request sends an article (title + content) in JSON

  • The test script runs all 3 analyses using the packages above

  • A custom HTML visualizer shows:

    • Detected language (e.g. “English”)
    • Sentiment score + label (e.g. “:blush: Positive”)
    • Generated summary

:camera_with_flash: Screenshots