xp-forge / frontend

Web frontends
1 stars 1 forks source link

Stream::of() #4

Closed thekid closed 5 years ago

thekid commented 6 years ago

This pull request adds the possibility to return streams from delegates.

use web\frontend\Stream;

class Users {
  // ...other delegates...

  #[@get('/users/{id}/avatar')]
  public function avatar($id) {
    return Stream::of('JFIF...', 'image/jpeg');
  }
}

The Stream::of() method will accept any of:

thekid commented 6 years ago

This could be implemented within the xp-forge/web library as follows:

use web\frontend\{Frontend, Templates};
use web\Application;

class Service extends Application {

  public function routes() {
    $templates= ...
    return [
      '/users/{user}/avatar' => function($req, $res) { ... },
      '/users'               => new Frontend(new Users(), $templates)
    ];
  }
}

The benefit would be that the avatar handler can use the full extent of the web API, including partial requests. The downside however is that possibly closely related code would be torn apart.

thekid commented 6 years ago

This could be implemented within the xp-forge/web library as follows [...]

See https://github.com/xp-forge/web/pull/37

thekid commented 5 years ago

Not necessary until now, can be reopened if necessary later on.