dryLang
docsplaygrounddownloadgithub

Getting Started

  • Home
  • Getting Started
  • Setup

Language Basics

  • Variables
  • Types
  • Operators
  • Comments
  • Strings

Control Flow

  • Control Flow
  • Loops

Advanced Concepts

  • Functions
  • Structs
  • Collections
  • Modules
  • HTTP Server
  • Database

Reference

  • Built-ins
  • Error Handling
  • Errors

Examples

  • Hello
  • Variables
  • Functions
  • Control Flow
  • Structs
  • Arrays Maps
  • Try Err
  • Imports
  • Math
  • Strings
  • Http Server
  • Database
  • File Io

Templates

  • Automation
  • Cli Tool
  • Crud
  • Fetch Json
  • File Server
  • Hello
  • Html Render
  • Rest Api
Docs Menu

Getting Started

  • Home
  • Getting Started
  • Setup

Language Basics

  • Variables
  • Types
  • Operators
  • Comments
  • Strings

Control Flow

  • Control Flow
  • Loops

Advanced Concepts

  • Functions
  • Structs
  • Collections
  • Modules
  • HTTP Server
  • Database

Reference

  • Built-ins
  • Error Handling
  • Errors

Examples

  • Hello
  • Variables
  • Functions
  • Control Flow
  • Structs
  • Arrays Maps
  • Try Err
  • Imports
  • Math
  • Strings
  • Http Server
  • Database
  • File Io

Templates

  • Automation
  • Cli Tool
  • Crud
  • Fetch Json
  • File Server
  • Hello
  • Html Render
  • Rest Api

Fetch Json

drylang
// template: fetch-json
// desc: Fetches data from a REST API and parses the JSON response

pt "Fetching random joke..."

try {
     // Make HTTP GET request
    resp = req("https://official-joke-api.appspot.com/random_joke")
    
     // Parse string into dryLang Map
    data = json(resp)
    
     // Extract fields
    setup = data["setup"]
    punchline = data["punchline"]
    
     // Display
    pt "Q: ${setup}"
    q(2000) // wait 2 seconds for effect
    pt "A: ${punchline}"
    
} err(e) {
    pt "Failed to fetch joke: ${e}"
}
PreviousCrudNextFile Server