Files
fn_registry/functions/infra/http_post_json.md
T
egutierrez 53200cbc0d feat: funciones Go — core (cron, join_by_key, validate_struct), datascience (pivot, diff_entities), infra (http, cache, cron_ticker)
Nuevas funciones Go con tests en tres dominios:
- core: parse_cron_expr, next_cron_time, join_by_key, validate_struct_fields + tipo CronSchedule
- datascience: pivot (tabla dinámica), diff_entities (comparación de entidades)
- infra: http_get_json, http_post_json, http_download_file, cache_to_sqlite, cron_ticker

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 17:11:12 +02:00

1.3 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path
http_post_json function go infra 1.0.0 impure func HttpPostJSON(url string, body any, headers map[string]string, timeout time.Duration) (map[string]any, error) POST request con body JSON serializado con json.Marshal. Agrega Content-Type: application/json y Accept: application/json. Retorna error con status code si >= 400.
http
json
post
client
network
stdlib
infra
false error_go_core
bytes
encoding/json
fmt
io
net/http
time
true
httptest.Server recibe body correcto
Status 201 → exito
Status 500 → error con body parcial
functions/infra/http_post_json_test.go functions/infra/http_post_json.go

Ejemplo

result, err := HttpPostJSON(
    "https://api.example.com/users",
    map[string]any{"name": "Alice", "role": "admin"},
    map[string]string{"X-Api-Key": "secret"},
    10*time.Second,
)
if err != nil {
    return nil, err
}
fmt.Println(result["id"])

Notas

Solo usa stdlib. El body acepta any y se serializa con json.Marshal. Headers custom se fusionan con Content-Type y Accept por defecto. El error incluye los primeros 200 bytes del body de respuesta.