Skip to content

Commit

Permalink
Update tutorials.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 20, 2024
1 parent 332dc82 commit f5c77bb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/docs/guide/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,50 @@ httpRegister("/calculation", $calculationHandler);

httpListen(":8080");

?>
```

### Build a simple HTTP server class
```php
<?davi
// DaVinci Script

$timeHandler = function() {
$time = time();
return($time);
}

$calculationHandler = function() {
return(5 + 5);
}

$homeHandler = function() {
return("Cool!");
}

$helloHandler = function() {
return("Hello, World!");
}

class HttpServer {

function route($path, $handler) {
httpRegister($path, $handler);
}

function run($port) {
httpListen($port);
}

}


$server = new HttpServer();
$server->route("/", $homeHandler);
$server->route("/hello", $helloHandler);
$server->route("/time", $timeHandler);
$server->route("/calculation", $calculationHandler);
$server->run(":8080");

?>
```

0 comments on commit f5c77bb

Please sign in to comment.