DEV Community

Donny Nguyen
Donny Nguyen

Posted on

DuckDuckGo Search API — Free to Use

Getting Started with DuckDuckGo Search API

The DuckDuckGo Search API gives you programmatic access to web search results without building your own web scraper. It returns organic results with titles, URLs, and snippets—perfect for building search features, content aggregators, or research tools.

What You Get

Each search returns:

  • Title: The result heading
  • URL: The full webpage link
  • Snippet: A preview of the page content
  • Configurable limits: Control how many results you need (up to your plan's limit)

No ads, no tracking—just clean search results from DuckDuckGo's privacy-focused index.

Real Code Example

Here's a simple fetch() implementation to search for "JavaScript tutorials":

const searchQuery = "JavaScript tutorials";
const limit = 10;

const options = {
  method: 'GET',
  headers: {
    'x-rapidapi-key': 'YOUR_RAPIDAPI_KEY',
    'x-rapidapi-host': 'duckduckgo-search-api-production.up.railway.app'
  }
};

fetch(`https://duckduckgo-search-api-production.up.railway.app/api/search?query=${encodeURIComponent(searchQuery)}&limit=${limit}`, options)
  .then(response => response.json())
  .then(data => {
    console.log('Search Results:');
    data.results.forEach(result => {
      console.log(`\nTitle: ${result.title}`);
      console.log(`URL: ${result.url}`);
      console.log(`Snippet: ${result.snippet}`);
    });
  })
  .catch(error => console.error('Error:', error));
Enter fullscreen mode Exit fullscreen mode

What's Happening

  1. Set your search query and result limit
  2. Add authentication headers (you'll get your API key from RapidAPI)
  3. Call the endpoint with your query as a URL parameter
  4. Parse the JSON response and access the results array
  5. Loop through results to display titles, URLs, and snippets

Pro Tips

  • URL encode special characters: Use encodeURIComponent() for queries with spaces or special chars
  • Rate limits matter: Check your RapidAPI plan for requests per month
  • Error handling: Always wrap API calls in try-catch blocks for production code
  • Cache results: Store searches locally to reduce API calls

Why DuckDuckGo?

Unlike some search APIs, DuckDuckGo focuses on privacy. No user tracking, no search history sales. If you're building tools that respect user privacy, this is a solid choice.

Next Steps

Ready to start building? Sign up for the DuckDuckGo Search API on RapidAPI. You'll get your API key immediately and can test endpoints directly from the dashboard.

Start with a simple search, then build it into your app. Happy coding!

Top comments (0)