Master Example (Combining Sections)

This example shows how a real flow uses almost all sections:

// SECTION I & II: Registration and Input
registerEndpoint("/v1/user", "POST", [], "Create User", main, final_res)

function main(){
    addParam("user", u)
    addParam("pass", p)
    
    // SECTION III & VI: Validation and Security
    if(u, None, "==")
        addVar(_status, 400)
        return("User is required")
    end()
    
    encodeSHA256(p, pass_hash)
    
    // SECTION IV: Asynchrony (Audit log)
    go_async("audit")
        ormDirect("INSERT INTO audit (event) VALUES ('User creation attempt')", r)
    end()
    
    // SECTION V: Persistence
    db = avapConnector("TOKEN_DB")
    res_db = db.query("INSERT INTO users (name, pass) VALUES ('%s', '%s')" % (u, pass_hash))
    
    // SECTION II: Response
    addVar(_status, 201)
    addResult(res_db)
    return(res_db)
}