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

Rest Api

drylang
// template: rest-api
// desc: REST API server with JSON responses and routing

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

PORT 8080
pt "API running on http://localhost:${PORT}"
op(PORT, handler, "mul", 100)
PreviousHtml Render