Skip to content

refactor(http): split HTTP_Send into smaller idiomatic FFI functions#84

Merged
akonwi merged 2 commits intomainfrom
refactor/http-ffi-simplification
Apr 10, 2026
Merged

refactor(http): split HTTP_Send into smaller idiomatic FFI functions#84
akonwi merged 2 commits intomainfrom
refactor/http-ffi-simplification

Conversation

@akonwi
Copy link
Copy Markdown
Owner

@akonwi akonwi commented Apr 10, 2026

Summary

Refactors the HTTP client FFI from one monolithic raw function into six smaller idiomatic functions, following the pattern outlined in docs/ffi-simplification.md.

Changes

Before

  • HTTP_Send was a 70-line raw FFI function that:
    • Manually unwrapped []*runtime.Object arguments
    • Built HTTP request
    • Executed request
    • Manually constructed Ard Response struct

After

Six small idiomatic FFI functions:

Function Signature Type
HTTP_Do (string, string, any, map[string]string, *int) (any, error) Idiomatic
HTTP_ResponseStatus (any) int Idiomatic
HTTP_ResponseHeader (any, string) *string Idiomatic
HTTP_ResponseHeaders (any) map[string]string Idiomatic
HTTP_ResponseBody (any) (string, error) Idiomatic
HTTP_ResponseClose (any) Idiomatic

Key Changes

  1. Added RawResponse opaque type (extern type) to safely pass *http.Response between Go and Ard
  2. Updated send() in std_lib/http.ard to orchestrate response building in Ard:
    • Calls http_do → gets RawResponse!Str
    • Extracts status, headers, body via accessor functions
    • Closes response handle explicitly
  3. All new FFI functions use idiomatic signatures (auto-generated wrappers in registry.gen.go)
  4. HTTP_Serve remains as-is (complex callback pattern with VM isolation)

Benefits

  • Simpler FFI - All HTTP client functions are idiomatic (no manual unwrapping)
  • Testable - Each function does one thing
  • Extensible - Easy to add more accessor functions
  • Separation of concerns - Go handles HTTP mechanics, Ard handles response construction

Testing

  • All unit tests pass
  • HTTP-specific tests pass (TestBytecodeHttpSendUsesRequestTimeout, etc.)
  • Server sample works correctly (samples/server.ard)
  • All curl endpoints verified

Documentation

Related: docs/ffi-simplification.md - FFI simplification analysis

akonwi added 2 commits April 10, 2026 15:35
- Add opaque RawResponse type for *http.Response handle
- Add HTTP_Do (makes request, returns handle)
- Add HTTP_ResponseStatus, HTTP_ResponseHeaders, HTTP_ResponseBody, HTTP_ResponseClose
- Remove HTTP_Send (was raw FFI, now replaced)
- Update send() in std_lib/http.ard to use new pattern:
  - Call http_do to get response handle
  - Extract status, headers, body via accessor functions
  - Close response handle explicitly
- All new FFI functions are idiomatic (auto-generated wrappers)
- HTTP_Serve remains as-is (complex callback pattern)
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ard-lang-dev Ready Ready Preview, Comment Apr 10, 2026 8:10pm

@akonwi akonwi merged commit 4105282 into main Apr 10, 2026
4 checks passed
@akonwi akonwi deleted the refactor/http-ffi-simplification branch April 10, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant