Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 104 additions & 104 deletions README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ results, err := client.Search(parameter)
fmt.Println(results)
```

This example runs a search for "coffee" on Google. It then returns the results a Go map.
This example runs a search for "coffee" on Google. It then returns the results as a Go map.
See the [playground](https://serpapi.com/playground) to generate your own code.

## Advanced Usage
### Search API
```golang

func main() {
// Initialize the client with custom setting
// Initialize the client with custom settings
setting := serpapi.NewSerpApiClientSetting("<SERPAPI_KEY>") // Replace with your SerpApi key
setting.Persistent = false // Enable persistent search
setting.Asynchronous = true // Enable asynchronous search
Expand All @@ -83,7 +83,7 @@ func main() {
"device": "desktop",
}

// formated search results as a map
//formatted search results as a map
// serpapi.com converts HTML -> JSON
rsp, err := client.Search(parameter)

Expand All @@ -92,8 +92,8 @@ func main() {
}
fmt.Println(rsp)

// raw search engine html as a String
// serpapi.com acts a proxy to provive high throughputs, no search limit and more.
// raw search engine HTML as a String
// serpapi.com acts as a proxy to provide high throughput, no search limit, and more.
raw_html, err := client.Html(parameter)
if err != nil {
panic(err)
Expand All @@ -103,7 +103,7 @@ func main() {
```

[Google search documentation](https://serpapi.com/search-api).
More hands on examples are available below.
More hands-on examples are available below.

#### Documentations

Expand Down Expand Up @@ -141,9 +141,9 @@ It prints the first 5 locations matching Austin (Texas, Texas, Rochester)
This API allows retrieving previous search results.
To fetch earlier results from the search_id.

First, you need to run a search and save the search id.
First, you need to run a search and save the search ID.
```golang
// First, you need to run a search and save the search id.
// First, you need to run a search and save the search ID.
auth := map[string]string{
"engine": "google",
"api_key": "secret_api_key",
Expand Down Expand Up @@ -195,175 +195,175 @@ It prints your account information.

## Basic examples in Go

### Search google
### Search Google
<%= snippet('golang', 'test/example/example_search_google_test.go') %>
* see: [serpapi.com/search-api](https://serpapi.com/search-api)
* See: [serpapi.com/search-api](https://serpapi.com/search-api)

### Search google light
### Search Google Light
<%= snippet('golang', 'test/example/example_search_google_light_test.go') %>
* see: [serpapi.com/google-light-api](https://serpapi.com/google-light-api)
* See: [serpapi.com/google-light-api](https://serpapi.com/google-light-api)

### Search google scholar
### Search Google Scholar
<%= snippet('golang', 'test/example/example_search_google_scholar_test.go') %>
* see: [serpapi.com/google-scholar-api](https://serpapi.com/google-scholar-api)
* See: [serpapi.com/google-scholar-api](https://serpapi.com/google-scholar-api)

### Search google autocomplete
### Search Google autocomplete
<%= snippet('golang', 'test/example/example_search_google_autocomplete_test.go') %>
* see: [serpapi.com/google-autocomplete-api](https://serpapi.com/google-autocomplete-api)
* See: [serpapi.com/google-autocomplete-api](https://serpapi.com/google-autocomplete-api)

### Search google product
### Search Google product
<%= snippet('golang', 'test/example/example_search_google_product_test.go') %>
* see: [serpapi.com/google-product-api](https://serpapi.com/google-product-api)
* See: [serpapi.com/google-product-api](https://serpapi.com/google-product-api)

### Search google reverse image
### Search Google reverse image
<%= snippet('golang', 'test/example/example_search_google_reverse_image_test.go') %>
* see: [serpapi.com/google-reverse-image](https://serpapi.com/google-reverse-image)
* See: [serpapi.com/google-reverse-image](https://serpapi.com/google-reverse-image)

### Search google events
### Search Google events
<%= snippet('golang', 'test/example/example_search_google_events_test.go') %>
* see: [serpapi.com/google-events-api](https://serpapi.com/google-events-api)
* See: [serpapi.com/google-events-api](https://serpapi.com/google-events-api)

### Search google local services
### Search Google local services
<%= snippet('golang', 'test/example/example_search_google_local_services_test.go') %>
* see: [serpapi.com/google-local-services-api](https://serpapi.com/google-local-services-api)
* See: [serpapi.com/google-local-services-api](https://serpapi.com/google-local-services-api)

### Search google maps
### Search Google Maps
<%= snippet('golang', 'test/example/example_search_google_maps_test.go') %>
* see: [serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)
* See: [serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)

### Search google jobs
### Search Google jobs
<%= snippet('golang', 'test/example/example_search_google_jobs_test.go') %>
* see: [serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
* See: [serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)

### Search google play
### Search Google Play
<%= snippet('golang', 'test/example/example_search_google_play_test.go') %>
* see: [serpapi.com/google-play-api](https://serpapi.com/google-play-api)
* See: [serpapi.com/google-play-api](https://serpapi.com/google-play-api)

### Search google images
### Search Google Images
<%= snippet('golang', 'test/example/example_search_google_images_test.go') %>
* see: [serpapi.com/images-results](https://serpapi.com/images-results)
* See: [serpapi.com/images-results](https://serpapi.com/images-results)

### Search google lens
### Search Google Lens
<%= snippet('golang', 'test/example/example_search_google_lens_test.go') %>
* see: [serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)
* See: [serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)

### Search google images light
### Search Google Images light
<%= snippet('golang', 'test/example/example_search_google_images_light_test.go') %>
* see: [serpapi.com/google-images-light-api](https://serpapi.com/google-images-light-api)
* See: [serpapi.com/google-images-light-api](https://serpapi.com/google-images-light-api)

### Search google hotels
### Search Google Hotels
<%= snippet('golang', 'test/example/example_search_google_hotels_test.go') %>
* see: [serpapi.com/google-hotels-api](https://serpapi.com/google-hotels-api)
* See: [serpapi.com/google-hotels-api](https://serpapi.com/google-hotels-api)

### Search google flights
### Search Google Flights
<%= snippet('golang', 'test/example/example_search_google_flights_test.go') %>
* see: [serpapi.com/google-flights-api](https://serpapi.com/google-flights-api)
* See: [serpapi.com/google-flights-api](https://serpapi.com/google-flights-api)

### Search google finance
### Search Google Finance
<%= snippet('golang', 'test/example/example_search_google_finance_test.go') %>
* see: [serpapi.com/google-finance-api](https://serpapi.com/google-finance-api)
* See: [serpapi.com/google-finance-api](https://serpapi.com/google-finance-api)

### Search google ai overview
### Search Google AI overview
<%= snippet('golang', 'test/example/example_search_google_ai_overview_test.go') %>
* see: [serpapi.com/google-ai-overview-api](https://serpapi.com/google-ai-overview-api)
* See: [serpapi.com/google-ai-overview-api](https://serpapi.com/google-ai-overview-api)

### Search google news
### Search Google News
<%= snippet('golang', 'test/example/example_search_google_news_test.go') %>
* see: [serpapi.com/google-news-api](https://serpapi.com/google-news-api)
* See: [serpapi.com/google-news-api](https://serpapi.com/google-news-api)

### Search google news light
### Search Google News light
<%= snippet('golang', 'test/example/example_search_google_news_light_test.go') %>
* see: [serpapi.com/google-news-light-api](https://serpapi.com/google-news-light-api)
* See: [serpapi.com/google-news-light-api](https://serpapi.com/google-news-light-api)

### Search google patents
### Search Google Patents
<%= snippet('golang', 'test/example/example_search_google_patents_test.go') %>
* see: [serpapi.com/google-patents-api](https://serpapi.com/google-patents-api)
* See: [serpapi.com/google-patents-api](https://serpapi.com/google-patents-api)

### Search google trends
### Search Google Trends
<%= snippet('golang', 'test/example/example_search_google_trends_test.go') %>
* see: [serpapi.com/google-trends-api](https://serpapi.com/google-trends-api)
* See: [serpapi.com/google-trends-api](https://serpapi.com/google-trends-api)

### Search google shopping
### Search Google Shopping
<%= snippet('golang', 'test/example/example_search_google_shopping_test.go') %>
* see: [serpapi.com/google-shopping-api](https://serpapi.com/google-shopping-api)
* See: [serpapi.com/google-shopping-api](https://serpapi.com/google-shopping-api)

### Search google immersive product
### Search Google immersive product
<%= snippet('golang', 'test/example/example_search_google_immersive_product_test.go') %>
* see: [serpapi.com/google-immersive-product-api](https://serpapi.com/google-immersive-product-api)
* See: [serpapi.com/google-immersive-product-api](https://serpapi.com/google-immersive-product-api)

### Search google videos
### Search Google videos
<%= snippet('golang', 'test/example/example_search_google_videos_test.go') %>
* see: [serpapi.com/google-videos-api](https://serpapi.com/google-videos-api)
* See: [serpapi.com/google-videos-api](https://serpapi.com/google-videos-api)

### Search amazon
### Search Amazon
<%= snippet('golang', 'test/example/example_search_amazon_test.go') %>
* see: [serpapi.com/amazon-search-api](https://serpapi.com/amazon-search-api)
* See: [serpapi.com/amazon-search-api](https://serpapi.com/amazon-search-api)

### Search baidu
### Search Baidu
<%= snippet('golang', 'test/example/example_search_baidu_test.go') %>
* see: [serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api)
* See: [serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api)

### Search yahoo
### Search Yahoo
<%= snippet('golang', 'test/example/example_search_yahoo_test.go') %>
* see: [serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api)
* See: [serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api)

### Search youtube
### Search YouTube
<%= snippet('golang', 'test/example/example_search_youtube_test.go') %>
* see: [serpapi.com/youtube-search-api](https://serpapi.com/youtube-search-api)
* See: [serpapi.com/youtube-search-api](https://serpapi.com/youtube-search-api)

### Search walmart
### Search Walmart
<%= snippet('golang', 'test/example/example_search_walmart_test.go') %>
* see: [serpapi.com/walmart-search-api](https://serpapi.com/walmart-search-api)
* See: [serpapi.com/walmart-search-api](https://serpapi.com/walmart-search-api)

### Search ebay
### Search eBay
<%= snippet('golang', 'test/example/example_search_ebay_test.go') %>
* see: [serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)
* See: [serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)

### Search naver
### Search Naver
<%= snippet('golang', 'test/example/example_search_naver_test.go') %>
* see: [serpapi.com/naver-search-api](https://serpapi.com/naver-search-api)
* See: [serpapi.com/naver-search-api](https://serpapi.com/naver-search-api)

### Search home depot
### Search Home Depot
<%= snippet('golang', 'test/example/example_search_home_depot_test.go') %>
* see: [serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-search-api)
* See: [serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-search-api)

### Search apple app store
### Search Apple App Store
<%= snippet('golang', 'test/example/example_search_apple_app_store_test.go') %>
* see: [serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)
* See: [serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)

### Search duckduckgo
### Search DuckDuckGo
<%= snippet('golang', 'test/example/example_search_duckduckgo_test.go') %>
* see: [serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-search-api)
* See: [serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-search-api)

### Search yandex
### Search Yandex
<%= snippet('golang', 'test/example/example_search_yandex_test.go') %>
* see: [serpapi.com/yandex-search-api](https://serpapi.com/yandex-search-api)
* See: [serpapi.com/yandex-search-api](https://serpapi.com/yandex-search-api)

### Search yelp
### Search Yelp
<%= snippet('golang', 'test/example/example_search_yelp_test.go') %>
* see: [serpapi.com/yelp-search-api](https://serpapi.com/yelp-search-api)
* See: [serpapi.com/yelp-search-api](https://serpapi.com/yelp-search-api)

## Advanced search API usage
### Highly scalable batching

Search API features non-blocking search using the option: `async=true`.
- Non-blocking - async=true - a single parent process can handle unlimited concurrent searches.
- Blocking - async=false - many processes must be forked and synchronized to handle concurrent searches. This strategy is I/O intensive because each client would hold a network connection.
- Blocking - async=false '): many processes must be forked and synchronized to handle concurrent searches. This strategy is I/O intensive because each client would hold a network connection.

Search API enables `async` search.
- Non-blocking (`async=true`) : the development is more complex, but this allows handling many simultaneous connections.
- Blocking (`async=false`) : it's easy to write the code but more compute-intensive when the parent process needs to hold many connections.
- Non-blocking (`async=true`): development is more complex, but this allows handling many simultaneous connections.
- Blocking (`async=false`): it's easy to write the code, but more compute-intensive when the parent process needs to hold many connections.

Here is an example of asynchronous searches using Go
<%= snippet('golang', 'demo/demo_async.go', true) %>

This code shows a simple solution to batch searches asynchronously into a [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)).
Each search takes a few seconds before completion by SerpApi service and the search engine. By the time the first element pops out of the queue. The search result might be already available in the archive. If not, the `search_archive` method blocks until the search results are available.
Each search takes a few seconds to complete via the SerpApi service and the search engine. By the time the first element pops out of the queue. The search result might already be available in the archive. If not, the `search_archive` method blocks until the search results are available.

## Supported Go version.
Go versions validated by Github Actions:
## Supported Go versions.
Go versions validated by GitHub Actions:
- 1.17+
* see: [Github Actions.](https://github.com/serpapi/serpapi-golang/actions/workflows/ci.yml)
* see: [GitHub Actions.](https://github.com/serpapi/serpapi-golang/actions/workflows/ci.yml)

## Change logs
* [2026-01-26] 1.1.0 Asynchronous & Persistent Mode Support
Expand All @@ -375,28 +375,28 @@ Go versions validated by Github Actions:

## Developer Guide
### Key goals
- Brand centric instead of search engine based
- Brand-centric instead of search engine-based
- No hard-coded logic per search engine
- Simple HTTP client (lightweight, reduced dependency)
- No magic default values
- Thread safe
- Thread-safe
- Easy extension
- Defensive code style (raise a custom exception)
- TDD
- Best API coding practice per platform
- KiSS principles
- KISS principles

### Inspirations
The source code and coding style of this project are inspired by Go.
The Go programming language provides native recommendations for building excellent software.

### Code quality expectations
- 0 lint offense: `make lint`
- 0 lint offenses: `make lint`
- 100% tests passing: `make test`
- 100% code coverage: `make test`

# Developer Guide
## Design : UML diagram
## Design: UML diagram
### Class diagram
```mermaid
classDiagram
Expand Down Expand Up @@ -428,25 +428,25 @@ sequenceDiagram
```
where:
- The end user implements the application.
- Client refers to serpapi.Client.
- Client refers to SerpApi.Client.
- SerpApi.com is the backend HTTP / REST service.
- Engine refers to Google, Baidu, Bing, and more.

The SerpApi.com service (backend)
- executes a scalable search on `engine: "google"` using the search query: `q: "coffee"`.
- parses the messy HTML responses from Google on the backend.
- returns a standardized JSON response.
The class serpapi.Client (client side / golang):
- Format the request to SerpApi.com server.
- Execute HTTP Get request.
- Parse JSON into Go map using a standard JSON library.
The class is SerpApi.Client (client-side / Golang):
- Formats the request to the SerpApi.com server.
- Executes an HTTP GET request.
- Parses JSON into a Go map using a standard JSON library.
Et voila!

## Continuous integration
We love "true open source" and "continuous integration", and Test Drive Development (TDD).
We are using Go test to test [our infrastructure around the clock]) using Github Action to achieve the best QoS (Quality Of Service).
We love "true open source" and "continuous integration", and Test-Driven Development (TDD).
We are using Go tests to test [our infrastructure around the clock]) using GitHub Actions to achieve the best QoS (Quality of Service).

The directory test/ includes specification which serves the dual purposes of examples and functional tests.
The directory test/ includes specification which serves the dual purpose of examples and functional tests.

Set your secret API key in your shell before running a test.
```bash
Expand All @@ -456,8 +456,8 @@ Install testing dependency
```bash
$ make test
```
Contributions are welcome. Feel to submit a pull request!
Contributions are welcome. Feel free to submit a pull request!

## License

MIT License.
MIT License.