a03675113a
- .claude/agents/fn-orquestador/SKILL.md - .claude/commands/fn_claude.md - .claude/rules/INDEX.md - .claude/rules/cpp_apps.md - .claude/rules/ids_naming.md - CHANGELOG.md - apps/dag_engine/README.md - apps/dag_engine/api.go - apps/dag_engine/dags_migrated/example.yaml - apps/dag_engine/dags_migrated/example_lineage_tracking.yaml - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.7 KiB
Markdown
54 lines
1.7 KiB
Markdown
---
|
|
name: http_post_json
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func HttpPostJSON(url string, body any, headers map[string]string, timeout time.Duration) (map[string]any, error)"
|
|
description: "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."
|
|
tags: [http, json, post, client, network, stdlib, infra, pendiente-usar, sink]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: ["bytes", "encoding/json", "fmt", "io", "net/http", "time"]
|
|
params:
|
|
- name: url
|
|
desc: "URL del endpoint HTTP"
|
|
- name: body
|
|
desc: "datos a serializar como JSON en el cuerpo de la solicitud"
|
|
- name: headers
|
|
desc: "mapa de headers custom a fusionar con los headers por defecto"
|
|
- name: timeout
|
|
desc: "duracion maxima para completar la solicitud"
|
|
output: "mapa con la estructura JSON decodificada del response"
|
|
tested: true
|
|
tests:
|
|
- "httptest.Server recibe body correcto"
|
|
- "Status 201 → exito"
|
|
- "Status 500 → error con body parcial"
|
|
test_file_path: "functions/infra/http_post_json_test.go"
|
|
file_path: "functions/infra/http_post_json.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
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.
|