summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwikiapiserver2026-06-26 01:32:11 +0200
committerwikiapiserver2026-06-26 01:32:11 +0200
commit46bcf2b5e837bfbc957db60a5c674742f3916083 (patch)
treefbfc7f8355da0a2ed696dfbcde3e6cc4bc78be03
parente7bbed2d3b7d06700b0b4d9009f695e0cdf03e40 (diff)
downloadwikiapiserver-46bcf2b5e837bfbc957db60a5c674742f3916083.tar.gz
fix: filter to English Wikipedia via POST with filter body
The structured contents API requires a POST request with the filter in the JSON body to narrow results: {"filters": [{"field": "in_language.identifier", "value": "en"}]} Replaces the non-functional query-string filter parameter.
-rw-r--r--api/handlers.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/api/handlers.go b/api/handlers.go
index d3a08fd..4299b74 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -3,6 +3,7 @@ package api
import (
"context"
"io"
+ "bytes"
"database/sql"
"errors"
"encoding/json"
@@ -228,14 +229,25 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) {
}
baseURL := "https://api.enterprise.wikimedia.com/v2/structured-contents/" + url.QueryEscape(article)
- queryURL := baseURL + "?limit=1"
- req, err := http.NewRequestWithContext(ctx, "GET", queryURL, nil)
+ body, err := json.Marshal(map[string]any{
+ "filters": []map[string]string{
+ {"field": "in_language.identifier", "value": "en"},
+ },
+ })
+ if err != nil {
+ serverError(w, "could not build request")
+ return
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "POST", baseURL, bytes.NewReader(body))
if err != nil {
serverError(w, "could not build request")
return
}
req.Header.Set("Authorization", "Bearer "+acct.AccessToken)
+ req.Header.Set("Content-Type", "application/json")
+ queryURL := baseURL
start := time.Now()
resp, err := http.DefaultClient.Do(req)