Proxy Endpoints¶
Base path: /api/v1/multi + router prefix /proxy → full base: /api/v1/multi/proxy
Summary: Manage local proxy records and Webshare (third-party proxy provider) credentials; test proxies via Selenium, fetch proxies from Webshare, and manage active/disabled flags. These endpoints are used by Selenium-based scrapers and monitor flows to obtain working proxies.
Auth: Bearer JWT required for all endpoints.
Primary models: Proxy, ProxyCreate, ProxyUpdate, ProxyTestRequest, ProxyTestResponse, WebshareCredentials, WebshareCredentialsCreate, WebshareCredentialsUpdate (see schemas.proxy and models.proxy).
External services used: services.webshare.get_proxies, services.webshare.test_key, selenium-wire for runtime proxy testing.
Endpoints (summary)¶
- POST / — Create a proxy (
ProxyCreate) and persist to DB. - GET / — List proxies (pagination:
skip,limit). - GET /{proxy_id} — Get proxy by ID.
- PUT /{proxy_id} — Update proxy record (
ProxyUpdate). - DELETE /clear — Remove all proxies from DB.
- DELETE /{proxy_id} — Remove a single proxy.
- POST /{proxy_id}/toggle-active/ — Toggle
activeflag on a proxy (returns new status).
Webshare credential management¶
- POST /webshare/credentials/ — Create Webshare credential (stored encrypted in DB).
- GET /webshare/credentials/ — List stored Webshare credentials.
- GET /webshare/credentials/{id} — Get a specific credential.
- PUT /webshare/credentials/{id} — Update a credential.
- DELETE /webshare/credentials/{id} — Delete a credential.
- POST /webshare/credentials/{id}/toggle-active — Toggle
activeon a credential (activating one deactivates others). - POST /webshare/test/ — Test a raw Webshare API key supplied in the request body.
- POST /webshare/credentials/{id}/test — Test a stored Webshare credential (DB key is decrypted before testing).
- POST /webshare/fetch/ — Fetch proxies from Webshare using the active credential and store any new proxies in DB.
Proxy runtime test¶
- POST /test — Test an existing proxy via a headless Selenium browser and
selenium-wire. The request body (ProxyTestRequest) includesproxy_idandurlto visit. ReturnsProxyTestResponsewithsuccess,message, detectedproxy_ipand a shortpage_content_preview.
Implementation details & behavior¶
fetch_webshare_proxies:- Retrieves the active Webshare credential from DB, decrypts the
api_keyviacore.security.decrypt_string, and callsservices.webshare.get_proxies(api_key). get_proxiespaginates the Webshare API (/proxy/list/), parses each entry intoProxyschemas and returns a list.-
The endpoint upserts any non-existing proxies into the
proxytable usingproxy_crud.get_by_host_port_user_passto deduplicate. -
test_webshare_credential/test_stored_webshare_credential: -
Use
services.webshare.test_key(api_key)which callshttps://proxy.webshare.io/api/v2/profile/to validate the token. Returns{ "success": true }on 200. -
test_proxy(Selenium-based): - Uses
selenium-wireto create a local proxy endpoint that forwards traffic through the target proxy. The code:- Starts selenium-wire with
seleniumwire_options(proxy config,addr='0.0.0.0',port=8087,auto_config=False). - Starts a remote Selenium WebDriver connected to
http://selenium:<SELENIUM_PORT>/wd/hub(envSELENIUM_PORT, default4444). - Visits
https://api.ipify.org?format=jsonto detect the public IP seen by the browser and optionally visits the providedurland returns a page preview. - Updates proxy status in DB with
proxy_crud.update_status(db, id=proxy.id, success=True|False).
- Starts selenium-wire with
- Note: The application monkey-patches
selenium.webdriver.Remote.__init__to removedesired_capabilitiesfor compatibility withselenium-wireand Selenium 4.10+.
Examples¶
- Test a raw Webshare API key:
curl -X POST "http://localhost:8000/api/v1/multi/proxy/webshare/test/" \
-H "Content-Type: application/json" \
-d '{"api_key": "WEBSHARE_API_KEY"}'
- Fetch proxies from Webshare (requires active Webshare credential stored in DB):
curl -X POST "http://localhost:8000/api/v1/multi/proxy/webshare/fetch/" \
-H "Authorization: Bearer <TOKEN>"
- Test a proxy via Selenium (proxy_id must exist):
curl -X POST "http://localhost:8000/api/v1/multi/proxy/test" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <TOKEN>" \
-d '{"proxy_id": 1, "url": "https://example.com"}'
Operational notes¶
- Ensure a Selenium hub/container is reachable at hostname
seleniumand port set bySELENIUM_PORT(default4444). The test flow expects to connect tohttp://selenium:<SELENIUM_PORT>/wd/hub. selenium-wirerequires binding a local port (default 8087). If running multiple concurrent proxy tests, ensure unique ports or serialize tests.- Stored Webshare
api_keyvalues are encrypted in the DB;webshare_crudhandles encryption/decryption for create/update, buttestendpoints explicitly decrypt viacore.security.decrypt_stringwhen reading. - Proxy tests perform real network requests and may reveal real IPs — avoid running tests with sensitive targets in production environments.
Links¶
- Endpoint implementation:
backend/service_multi-repricer/app/api/v1/endpoints/proxy.py - Webshare service:
backend/service_multi-repricer/app/services/webshare.py - Proxy CRUD:
backend/service_multi-repricer/app/crud/proxy.py
Generated: detailed reference for proxy endpoints used by multi-repricer.