🐹 @http Operator in TuskLang - Go Guide

Go Documentation

@http Operator in TuskLang - Go Guide

🌐 Web Power: @http Operator Unleashed

TuskLang's @http operator is your internet rebellion. We don't bow to any kingβ€”not even the web. Here's how to use @http in Go projects to make HTTP requests, consume APIs, and fetch external data directly from your configuration.

πŸ“‹ Table of Contents

- What is @http? - Basic Usage - HTTP Methods - Authentication - Go Integration - Best Practices

🌍 What is @http?

The @http operator makes HTTP requests and injects the responses directly into your config. No more external API calls in your codeβ€”just pure, config-driven web power.

πŸ› οΈ Basic Usage

[external]
api_status: @http("GET", "https://api.example.com/status")
weather: @http("GET", "https://api.weather.com/current")
user_data: @http("POST", "https://api.example.com/users", {"name": "John"})

πŸ”§ HTTP Methods

GET Requests

[api]
status: @http("GET", "https://api.example.com/health")
users: @http("GET", "https://api.example.com/users")

POST Requests

[create]
new_user: @http("POST", "https://api.example.com/users", {"name": "Alice", "email": "alice@example.com"})

PUT Requests

[update]
update_user: @http("PUT", "https://api.example.com/users/123", {"name": "Bob"})

DELETE Requests

[delete]
remove_user: @http("DELETE", "https://api.example.com/users/123")

πŸ” Authentication

[authenticated]
user_profile: @http("GET", "https://api.example.com/profile", {}, {"Authorization": "Bearer token123"})

πŸ”— Go Integration

apiStatus := config.GetString("api_status")
weather := config.GetString("weather")

Manual HTTP Client

client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get("https://api.example.com/status")
if err != nil {
    log.Fatal(err)
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) }

πŸ₯‡ Best Practices

- Use HTTPS for all external requests - Set appropriate timeouts - Handle HTTP errors gracefully - Cache external API responses with @cache - Validate response data

---

TuskLang: Web power in your config with @http.