Skip to content

Commit faca477

Browse files
committed
Update README
1 parent 291b207 commit faca477

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@ await getJson({ engine: "google", q: "coffee" }); // uses the API key defined in
114114
await getJson({ engine: "google", api_key: API_KEY_2, q: "coffee" }); // API_KEY_2 will be used
115115
```
116116

117+
### Using a Proxy
118+
119+
You can use a proxy by passing `requestOptions` with an `HttpsProxyAgent`
120+
instance. This can be done either globally through the config object or
121+
per-request in the parameters.
122+
123+
First, install the required package:
124+
125+
```bash
126+
npm install https-proxy-agent
127+
```
128+
129+
Then use it in your code:
130+
131+
```js
132+
import { config, getJson } from "serpapi";
133+
import { HttpsProxyAgent } from "https-proxy-agent";
134+
135+
// Global configuration
136+
config.requestOptions = {
137+
agent: new HttpsProxyAgent("http://proxy-server:port"),
138+
};
139+
140+
// Or per-request configuration
141+
await getJson({
142+
engine: "google",
143+
q: "coffee",
144+
requestOptions: {
145+
agent: new HttpsProxyAgent("http://proxy-server:port"),
146+
},
147+
});
148+
```
149+
117150
## Pagination
118151

119152
Built-in pagination is not supported. Please refer to our pagination examples

0 commit comments

Comments
 (0)