Download the PHP package modulework/http without Composer
On this page you can find all versions of the php package modulework/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download modulework/http
More information about modulework/http
Files in modulework/http
Package http
Short Description HTTP package for the MODULEWork Framework
License MIT
Informations about the package http
HTTP Package
The HTTP Package of the Modulework Framework.
It provides a convient way of handling HTTP request and HTTP response.
So for example you could already create a application with these two classes:
This will app will great every vistor with their name or if the vistor didn' t provide the name in the query string it will fallback to "Stranger".
Of course this is a very basic example but it can do a lot more!
We could expand this and save the name into a cookie:
Or check if the method is GET or POST, so a user could also POST it' s name:
Or display the client' s IP:
Now we also send a cookie a too the user. But we can do even more:
Chained methods! Custom Headers! Custom Status Codes! And much more!
The Response class is intelligent enough to set the status code, if a redirect is issued:
Will result in this header
But the Request class can do even more, we can use it for very basic routing:
This is very basic and not best practice, but it shows for what we can use this class for!
There are also some more Response classes, like the RedirectResponse and JsonResponse class.
Here is an usage example:
As you can see very easy to use. NOTE! This is just a wrapper for a normal Response. You could also do this:
The only thing what is not shown in the alternative way is the HTML meta redirect (in case the header doesn' t fire).
The JsonResponse class is pretty straight forward as well:
This would result in this response:
Pretty nifty, eeh!!?