πΉ @http Operator in TuskLang - Go Guide
@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.