-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Send Example | ||
|
||
This example demonstrates how to return different types of responses with Dumbo. | ||
|
||
## Running the Example | ||
|
||
1. Install dependencies: | ||
|
||
```bash | ||
composer install | ||
``` | ||
|
||
2. Start the server: | ||
|
||
```bash | ||
composer start | ||
``` | ||
|
||
3. Access the different routes: | ||
|
||
```bash | ||
# Get the SVG | ||
curl -i http://localhost:8000/logo > logo.svg | ||
|
||
# Get the JPEG | ||
curl -i http://localhost:8000/image > image.jpeg | ||
|
||
# Get the README | ||
curl -i http://localhost:8000/readme | ||
|
||
# Get the CSV | ||
curl -i http://localhost:8000/export > users.csv | ||
|
||
# Get the XML | ||
curl -i http://localhost:8000/feed | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"require": { | ||
"notrab/dumbo": "@dev" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "../../" | ||
} | ||
], | ||
"scripts": { | ||
"start": [ | ||
"Composer\\Config::disableProcessTimeout", | ||
"php -S localhost:8000 -t ." | ||
] | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
|
||
use Dumbo\Dumbo; | ||
|
||
$app = new Dumbo(); | ||
|
||
$app->get("/", function ($c) { | ||
$html = <<<HTML | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>File Type Examples</title> | ||
</head> | ||
<body> | ||
<h1>File Type Examples</h1> | ||
<ul> | ||
<li><a href="/logo">SVG</a> (image/svg+xml)</li> | ||
<li><a href="/image">Image</a> (image/jpeg)</li> | ||
<li><a href="/readme">README</a> (text/plain)</li> | ||
<li><a href="/export">CSV Export</a> (text/csv)</li> | ||
<li><a href="/feed">XML Feed</a> (application/xml)</li> | ||
</ul> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
return $c->html($html); | ||
}); | ||
|
||
$app->get("/logo", function ($c) { | ||
$svg = <<<SVG | ||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"> | ||
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="purple" /> | ||
</svg> | ||
SVG; | ||
|
||
return $c->send($svg, "image/svg+xml"); | ||
}); | ||
|
||
$app->get("/image", function ($c) { | ||
$png = file_get_contents(__DIR__ . "/dumbo.jpeg"); | ||
return $c->send($png, "image/jpeg"); | ||
}); | ||
|
||
$app->get("/readme", function ($c) { | ||
$text = file_get_contents(__DIR__ . "/README.md"); | ||
return $c->send($text, "text/plain"); | ||
}); | ||
|
||
$app->get("/export", function ($c) { | ||
$csv = "Name,Email,Role\n"; | ||
$csv .= "John Doe,john@example.com,Admin\n"; | ||
$csv .= "Jane Smith,jane@example.com,User\n"; | ||
|
||
return $c->send($csv, "text/csv", 200, [ | ||
"Content-Disposition" => 'attachment; filename="users.csv"', | ||
]); | ||
}); | ||
|
||
$app->get("/feed", function ($c) { | ||
$xml = <<<XML | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>My Feed</title> | ||
<description>Latest updates</description> | ||
<item> | ||
<title>New Feature</title> | ||
<description>Check out our latest feature!</description> | ||
</item> | ||
</channel> | ||
</rss> | ||
XML; | ||
|
||
return $c->send($xml, "application/xml"); | ||
}); | ||
|
||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters