Tutorial

How to Build a REST API Wrapping Scavio Reddit with Recency and Demand Scoring

Build a REST API over Scavio Reddit endpoint with recency filtering and demand scoring. FastAPI tutorial for side project validation.

An r/SideProject post asked for a tool that checks Reddit demand with recency filters. This tutorial builds that tool as a REST API: it wraps Scavio's Reddit endpoint, adds configurable recency windows (1d, 7d, 30d), and scores demand intensity. Deploy it and you have a reusable validation endpoint.

Prerequisites

  • Scavio API key
  • Python 3.8+ with FastAPI
  • uvicorn for serving

Walkthrough

Step 1: Set up FastAPI project

Minimal API with one endpoint.

Python
from fastapi import FastAPI, Query
from pydantic import BaseModel
from datetime import datetime, timedelta
import requests, os

app = FastAPI(title='Reddit Demand API')
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

class DemandResult(BaseModel):
    query: str
    window: str
    post_count: int
    demand_score: int
    top_posts: list

Step 2: Build the demand endpoint

Single endpoint with recency filter parameter.

Python
@app.get('/demand', response_model=DemandResult)
async def check_demand(
    query: str,
    window: str = Query('7d', regex='^(1d|7d|30d)$')
):
    data = requests.post('https://api.scavio.dev/api/v1/search',
        headers=H,
        json={'platform': 'reddit', 'query': query, 'sort': 'new'}).json()
    results = data.get('results', [])
    # Filter by recency
    days = {'1d': 1, '7d': 7, '30d': 30}[window]
    cutoff = datetime.now() - timedelta(days=days)
    recent = []
    for r in results:
        post_date = r.get('date', '')
        if post_date:
            try:
                dt = datetime.fromisoformat(post_date.replace('Z', '+00:00'))
                if dt.replace(tzinfo=None) >= cutoff:
                    recent.append(r)
            except ValueError:
                continue
    # Score demand
    score = sum(r.get('upvotes', 0) + r.get('comments', 0) * 2 for r in recent)
    return DemandResult(
        query=query, window=window, post_count=len(recent),
        demand_score=score,
        top_posts=[{'title': r.get('title', ''), 'upvotes': r.get('upvotes', 0),
            'subreddit': r.get('subreddit', ''), 'url': r.get('url', '')}
            for r in recent[:10]])

Step 3: Add batch validation endpoint

Check multiple ideas at once.

Python
@app.post('/demand/batch')
async def batch_demand(queries: list[str], window: str = '7d'):
    results = []
    for q in queries:
        result = await check_demand(q, window)
        results.append(result)
    # Sort by demand score descending
    results.sort(key=lambda x: x.demand_score, reverse=True)
    return results

Step 4: Run the server

Start the API with uvicorn.

Bash
# Install: pip install fastapi uvicorn requests
# Run: uvicorn demand_api:app --reload --port 8000
#
# Test: curl 'http://localhost:8000/demand?query=invoice+tool&window=7d'
#
# Cost: each demand check = 1 Scavio query = $0.005

Python Example

Python
# Full demand API server:
# pip install fastapi uvicorn requests
# uvicorn demand_api:app --port 8000
#
# GET /demand?query=crm+for+freelancers&window=7d
# POST /demand/batch with ["idea1", "idea2", "idea3"]
#
# Each check: 1 query = $0.005 via Scavio

JavaScript Example

JavaScript
// Call the demand API from JS:
const res = await fetch('http://localhost:8000/demand?query=invoice+tool&window=7d');
const data = await res.json();
console.log(`Demand score: ${data.demand_score}, Posts: ${data.post_count}`);

Expected Output

JSON
REST API at /demand with recency filtering (1d/7d/30d) and demand scoring. Batch endpoint for validating multiple ideas. Each query costs $0.005.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Scavio API key. Python 3.8+ with FastAPI. uvicorn for serving. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build a REST API over Scavio Reddit endpoint with recency filtering and demand scoring. FastAPI tutorial for side project validation.