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

HTTP Server

dryLang has a built-in HTTP server powered by Go's net/http. Start one with a single function call.

op() — Start Server

drylang
op(port, handler, mode, maxWorkers)
ParamTypeRequiredDescription
portnumber✅Port to listen on
handlerfunction✅Request handler function
modestring❌"uni" (default) or "mul"
maxWorkersnumber❌Max concurrent workers (default: 100)

Modes

  • "uni" — Single-threaded with mutex locking. Requests are processed one at a time. Safe for shared state.
  • "mul" — Multi-threaded. Each request gets a fresh VM clone with shared globals. Use for high-throughput APIs.

Handler Function

The handler receives a request map and must rev (return) a response.

Request Map

drylang
fn handler(req) {
    pt req["method"]    // "G", "PO", "PUT", "PAT", "DEL", "OPT", "H"
    pt req["path"]      // "/api/users"
    pt req["body"]      // request body string
    pt req["query"]     // map of query parameters
}

HTTP Method Mappings (shortened for dryLang):

HTTP MethoddryLang
GET"G"
POST"PO"
PUT"PUT"
PATCH"PAT"
DELETE"DEL"
OPTIONS"OPT"
HEAD"H"

Response

Return a string for simple text response:

drylang
fn handler(req) {
    rev "Hello, World!"
}

Return a map for custom status and body:

drylang
fn handler(req) {
    rev {
        "status": 200,
        "body": "{\"message\": \"success\"}"
    }
}

Complete Example

drylang
fn handler(req) {
    if req["method"] = "G" & req["path"] = "/" {
        rev {
            "status": 200,
            "body": "{\"message\": \"Welcome to dryLang API\"}"
        }
    } elif req["method"] = "PO" & req["path"] = "/echo" {
        rev {
            "status": 200,
            "body": req["body"]
        }
    } el {
        rev {
            "status": 404,
            "body": "{\"error\": \"not found\"}"
        }
    }
}

pt "API running on http://localhost:8080"
op(8080, handler, "mul", 100)

Notes

  • op() is blocking — it runs indefinitely until the process is killed.
  • In "mul" mode, globals are shared across requests (useful for in-memory state).
  • The server prints a startup message: Starting dryLang server on port XXXX (mode: yyy)...
PreviousModulesNextDatabase