A minimalist, modern command-line based tool for querying SerpApi designed for advanced users who love to use SerpApi for data analyzing and web scraping.
To get started with this awesome project, you can follow these simple steps:
| Prerequisites | Requirement | Purpose |
|---|---|---|
| .NET SDK | .NET 8.0 SDK or later | Compiles and executes the project (dotnet --version >= 8.0) |
| Operating System | Windows, macOS or Linux | Cross-platform support |
| Terminal | Any modern terminal with ANSI / UTF-8 support | Renders ANSI colors, spinners, tables... |
| IDE / Editor (Optional) | VS Code, Visual Studio or JetBrains Rider | For development and debugging |
-
Clone the repository
-
Install dependencies:
dotnet restoreTo run a query using this program:
- Navigate to the
SerpApi.Cliproject
cd src/SerpApi.Cli- Create a
.envfile in the project
SERPAPI_API_KEY="Your SerpApi key here"- Run the command
dotnet run -- -q "Coffee" -p hl=en -p gl=usAnd there you have it! Your first seach query with this CLI tool!
- Basic Search:
dotnet run -- -q "best coffee" - Localized Search: Passing language and country codes (
-p hl=km-kh -p gl=kh) - Engine Tuning: Passing result limits and device views (
-p num=50 -p device=mobile) - Flag Reference Table:
-q, --query <QUERY>: Primary search string.-k, --api-key <KEY>: Override and set API Key.-p, --param <PARAM>: Arbitrary SerpApi key-value parameters.
Tests run completely in-memory using mocked HTTP handlers—no internet connection or SerpApi credits required. To conduct tests for this project, you can use dotnet test to test out the functionalities and see if the program is working properly.
See what's already been covered:
- URL query serialization and deserialization.
- JSON response mapping to strongly-typed records.
- Parameter alias normalization (
host_language -> h1).
Quickly grasp the idea behind the software architecture in this project:
- Dependency Injection: Instead of tightly coupling classes with
new HttpClient(), services are registered viaMicrosoft.Extensions.DependencyInjection. This allows commands to depend on abstractions (ISerpApiClient), simplifies unit testing with mocks, and managesHttpClientlifecycles properly. - Typed-Dictionary Parameters: Instead of manually writing a parameter name like
hl=enwith no type-safety, Parameters are pre-defined as properties inSearchParametersclass. This simplifies typing by taking the advantage of the C# features, and significantly improving developer experience overall.
