xp-framework / scriptlet
Scriptlets for the XP Framework
Installs: 65 198
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 15
Forks: 4
Open Issues: 0
Requires
- php: >=5.6.0
- xp-framework/core: ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/http: ^9.0 | ^8.0 | ^7.0 | ^6.2
- xp-framework/logging: ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/mail: ^8.0 | ^7.0 | ^6.1
- xp-framework/networking: ^9.0 | ^8.0 | ^7.0 | ^6.6
- xp-framework/rdbms: ^12.0 | ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/xml: ^9.0 | ^8.0 |^7.0 | ^6.3
Requires (Dev)
- xp-framework/unittest: ^9.0 | ^8.0 | 7.0 | ^6.5
- dev-master
- v9.2.2
- v9.2.1
- v9.2.0
- v9.1.1
- v9.1.0
- v9.0.0
- v8.5.0
- v8.4.6
- v8.4.5
- v8.4.4
- v8.4.3
- v8.4.2
- v8.4.1
- v8.4.0
- v8.3.3
- v8.3.2
- v8.3.1
- v8.3.0
- v8.2.5
- v8.2.4
- v8.2.3
- v8.2.2
- v8.2.1
- v8.2.0
- v8.1.2
- v8.1.1
- v8.1.0
- v8.0.2
- v8.0.1
- 8.0.0.x-dev
- v8.0.0
- v7.1.0
- v7.0.1
- 7.0.0.x-dev
- v7.0.0
- v6.3.2
- v6.3.1
- v6.3.0
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.3
- v6.0.2
- v6.0.0
- v2.0.1
- dev-cancel-in-setup
- dev-feature/routing
- dev-web-debugging
This package is auto-updated.
Last update: 2020-08-29 04:49:10 UTC
README
Everything that runs in the web in the XP Framework, is a scriptlet, at the beginning. Every higher-class API is derived from the simple HttpScriptlet
class: RestScriptlet
, WorkflowScriptlet
, ...
The HttpScriptlet class
The scriptlet.HttpScriptlet
class is the base class for any so-called scriptlet. A scriptlet is something that can serve HTTP requests.
The simplest form of answering an HTTP request in XP Framework goes like this:
namespace com\example\web; class HelloScriptlet extends \scriptlet\HttpScriptlet { /** * Perform GET request * * @param scriptlet.Request $request * @param scriptlet.Response $response * @throws scriptlet.ScriptletException */ public function doGet($request, $response) { $response->write(sprintf('<!DOCTYPE html> <html> <head><title>Hello World scriptlet</title></head> <body> <h1>Hello %s</h1> </body> </html>', htmlspecialchars($request->getParam('name', 'World')) )); } }
This code generates a HTML page that shows a headline "Hello World" or "Hello $something" when something was given as GET-parameter "name".
Override doPost()
or any of the other methods named after HTTP request types to serve these request types, as well.
Running it
Use the xp web
runner to serve your scriptlet:
$ xp web com.example.web.HelloScriptlet [xpws-dev#7312] running localhost:8080 @ /path/to/web/project - Press <Enter> to exit
Now open http://localhost:8080/ in your browser.