Skip to content

yigitkonur/sdk-deno-serper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

type-safe Deno client for the Serper.dev Google Search API. ten endpoints, zero dependencies, strict TypeScript throughout.

import { SerperClient } from "jsr:@yigitkonur/sdk-deno-serper";

const client = new SerperClient({ apiKey: Deno.env.get("SERPER_API_KEY")! });
const results = await client.search("your query");

JSR deno license


what it does

  • 10 search endpoints — web, images, news, videos, shopping, maps, reviews, scholar, patents, autocomplete
  • zero runtime dependencies — only web standard APIs (fetch, AbortController)
  • strict types — readonly result arrays, noUncheckedIndexedAccess, true private fields via #
  • typed error hierarchy — auth, rate limit, validation, server errors with proper instanceof chains
  • timeout + abort — configurable per-client, defaults to 30s
  • default merging — set country/language once on the client, override per-request

install

deno add jsr:@yigitkonur/sdk-deno-serper

or import directly without install:

import { SerperClient } from "jsr:@yigitkonur/sdk-deno-serper@1.0.2";

usage

web search

const results = await client.search("rust async runtime", {
  num: 5,
  gl: "us",
  tbs: "qdr:w", // past week
});

images

const images = await client.searchImages("aurora borealis", { safe: "active" });

news / videos / shopping

const news = await client.searchNews("deno 2.0");
const videos = await client.searchVideos("systems programming");
const shopping = await client.searchShopping("mechanical keyboard");

maps + reviews

const places = await client.searchMaps("coffee shops", { location: "Brooklyn, NY" });
const reviews = await client.getReviews({ placeId: "ChIJ..." });

scholar + patents

const papers = await client.searchScholar("transformer architecture", {
  as_ylo: 2023, // published after 2023
});
const patents = await client.searchPatents("solid state battery");

autocomplete

const suggestions = await client.autocomplete("how to");

endpoints

method endpoint description
search /search web search (organic, knowledge graph, answer box, people also ask)
searchImages /images image results with dimensions and source
searchNews /news news articles with source and date
searchVideos /videos video results (YouTube, etc.)
searchShopping /shopping products with price and seller
searchMaps /maps local businesses with lat/lng, rating, phone
searchPlaces /maps alias for searchMaps
getReviews /reviews place reviews with ratings and pagination
searchScholar /scholar academic papers with optional PDF links
searchPatents /patents patent filings with abstract and publication date
autocomplete /autocomplete search suggestions

client options

const client = new SerperClient({
  apiKey: "...",              // required
  baseUrl: "...",             // default: https://google.serper.dev
  defaultCountry: "us",      // applied as `gl` to all requests
  defaultLanguage: "en",     // applied as `hl` to all requests
  timeout: 15_000,           // ms, default: 30_000
});

per-request options override client defaults.

error handling

import {
  SerperAuthError,
  SerperRateLimitError,
  SerperValidationError,
  SerperServerError,
} from "jsr:@yigitkonur/sdk-deno-serper";

try {
  await client.search("query");
} catch (e) {
  if (e instanceof SerperRateLimitError) {
    // 429 — back off
  } else if (e instanceof SerperAuthError) {
    // 401/403 — bad key
  } else if (e instanceof SerperValidationError) {
    // 4xx or empty query
  } else if (e instanceof SerperServerError) {
    // 5xx, timeout, network
  }
}

all errors extend SerperError which extends Error. each carries a .status number.

supabase edge functions

the repo includes 10 ready-to-deploy Supabase Edge Functions in supabase/functions/, one per endpoint. import map points to JSR:

{ "imports": { "@yigitkonur/sdk-deno-serper": "jsr:@yigitkonur/sdk-deno-serper@1.0.2" } }
supabase functions deploy serper-web-search

development

deno task all         # fmt + lint + check + test
deno task test        # run tests
deno task bump:patch  # bump version, commit, tag

license

MIT

About

type-safe Deno client for Serper.dev — 10 Google Search endpoints, zero deps

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors