Files
fn_registry/functions/infra/http_get_json.md
T
egutierrez cfdf515228 chore: auto-commit (799 archivos)
- .claude/CLAUDE.md
- .claude/commands/subagentes.md
- .claude/rules/INDEX.md
- .mcp.json
- bash/functions/cybersecurity/analyze_dns.md
- bash/functions/cybersecurity/audit_http_headers.md
- bash/functions/cybersecurity/audit_ssh_config.md
- bash/functions/cybersecurity/check_firewall.md
- bash/functions/cybersecurity/detect_suspicious_users.md
- bash/functions/cybersecurity/encrypt_file.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 00:28:20 +02:00

52 lines
1.6 KiB
Markdown

---
name: http_get_json
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func HttpGetJSON(url string, headers map[string]string, timeout time.Duration) (map[string]any, error)"
description: "GET request que espera JSON. Agrega Accept: application/json automaticamente. Retorna error con status code si >= 400. Siempre cierra body con defer."
tags: [http, json, get, client, network, stdlib, infra, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: ["encoding/json", "fmt", "io", "net/http", "time"]
params:
- name: url
desc: "URL del endpoint HTTP a consultar"
- name: headers
desc: "mapa de headers custom a incluir en la solicitud"
- name: timeout
desc: "duracion maxima para completar la solicitud"
output: "mapa con la estructura JSON decodificada del response"
tested: true
tests:
- "httptest.Server con respuesta JSON"
- "Status 404 → error"
- "Timeout → error"
- "Headers custom"
test_file_path: "functions/infra/http_get_json_test.go"
file_path: "functions/infra/http_get_json.go"
---
## Ejemplo
```go
result, err := HttpGetJSON(
"https://api.example.com/users",
map[string]string{"X-Api-Key": "secret"},
10*time.Second,
)
if err != nil {
return nil, err
}
fmt.Println(result["total"])
```
## Notas
Solo usa stdlib (net/http, encoding/json). El timeout se configura en el http.Client. El error incluye los primeros 200 bytes del body para facilitar debugging. Los headers custom se fusionan con Accept: application/json (custom tiene precedencia).