Add HTTP fetch support with libcurl integration#1
Open
TomasPalsson wants to merge 1 commit into
Open
Conversation
Add `fetch` keyword for making HTTP requests directly from Bonk code. Supports GET/POST/PUT/DELETE via a libcurl-based C runtime. Syntax: fetch "url" -- GET request fetch "POST" "url" "body" -- method + URL + body result = fetch "url"; -- capture response as string https://claude.ai/code/session_01M76SM5XsfmERRhkueq1d4W
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds HTTP fetch capabilities to the Bonk language, enabling HTTP requests (GET, POST, DELETE, etc.) with optional request bodies. The feature is implemented as both an expression and statement, with responses returned as strings.
Key Changes
New
fetchkeyword and syntax: Supports 1-3 argument forms:fetch URL— implicit GET requestfetch METHOD URL— custom HTTP method, no bodyfetch METHOD URL BODY— custom method with request bodyC runtime library (
runtime/http.c):bonk_http_fetch()function using libcurlParser enhancements (
src/parser.rs):Token::Fetchlexingparse_fetch_statement()andparse_fetch_args()for flexible argument parsingAST extensions (
src/ast.rs):Statement::FetchvariantExpression::Fetchvariant with method, url, and optional bodyCompiler codegen (
src/compiler.rs):compile_fetch()to emit x86-64 calling convention setup (rdi/rsi/rdx)string_varstracking to distinguish string-valued variables for proper printf formattingcompile_print()to use correct format string for fetch results and string variables_bonk_http_fetchsymbolBuild system (
Makefile):http.c-lcurl)Documentation (
CLAUDE.md):Example (
examples/http.bonk):Implementation Details
fmt_strformat for string values)https://claude.ai/code/session_01M76SM5XsfmERRhkueq1d4W