<commit_before># Usage Examples

Below are several usage examples, covering a variety of ways of creating and
managing an application.

In all examples, the assumption is the following directory structure:

```
.
├── config
├── data
├── composer.json
├── public
│   └── index.php
├── src
└── vendor
```

We assume also that:

- You have installed zend-expressive per the installation instructions.
- `public/` will be the document root of your application.
- Your own classes are under `src/` with the top-level namespace `Application`,
  and you have configured autoloading in your `composer.json` for those classes.

> ## Using the built-in web server
>
> You can use the built-in web server to run the examples. Run:
>
> ```bash
> $ php -S 0:8080 -t public/
> ```
>
> from the application root to start up a web server running on port 8080, and
> then browse to http://localhost:8080

## Hello World

In this example, we assume the defaults are fine, and simply grab an application
instance, add routes to it, and run it.

Put the code below in your `public/index.php`:

```php
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/', function ($req, $res, $next) {
    $res->write('Hello, world!');<commit_msg>Windows friendly built-in server command<commit_after># Usage Examples

Below are several usage examples, covering a variety of ways of creating and
managing an application.

In all examples, the assumption is the following directory structure:

```
.
├── config
├── data
├── composer.json
├── public
│   └── index.php
├── src
└── vendor
```

We assume also that:

- You have installed zend-expressive per the installation instructions.
- `public/` will be the document root of your application.
- Your own classes are under `src/` with the top-level namespace `Application`,
  and you have configured autoloading in your `composer.json` for those classes.

> ## Using the built-in web server
>
> You can use the built-in web server to run the examples. Run:
>
> ```bash
> $ php -S 0.0.0.0:8080 -t public
> ```
>
> from the application root to start up a web server running on port 8080, and
> then browse to http://localhost:8080

## Hello World

In this example, we assume the defaults are fine, and simply grab an application
instance, add routes to it, and run it.

Put the code below in your `public/index.php`:

```php
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/', function ($req, $res, $next) {
    $res->write('Hello, world!');
{'fraction_non_alphanumeric': 0.11837191934279313, 'fraction_numerical': 0.010828976848394324, 'mean_word_length': 4.054716981132075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7027453', 'n_tokens_mistral': 834, 'n_tokens_neox': 805, 'n_words': 357}