BOTK Core package samples

Running samples

To execute samples in this dir:
  1. If not already done, download and install dependencies in project home: 
    cd ..; curl -s http://getcomposer.org/installer | php;php composer.phar install
  2. Configure a php enabled web server to publish samples directory and point browser to it. This file should be shown.
  3. Click links to run examples.
  4. See sources.
  5. Play with http headers (i.e. Accepts) and http methods using an interactive  REST client compatible with your browser (here an example for chrome).

simple_helloword.php

This script is a minimal standalone endpoint implementation just to demonstrate how to build autocontained web service using  just Core classes.

It manages HTTP content negotiation supporting following formats:

It manages http error according providing ietf error model in following formats:

click here to execute   

restful_helloworld.php

This script is a complete standalone endpoint implementation just to demonstrate how to build autocontained RESTful using Core classes.Similar to simple_helloworld.php but shows usage of hypermedia links.

click here to execute

reusable_helloworld.php

It shows how easy is to develop a web application that reuse an existing end-point. Reused endpoint is contained in a single file ( in mylibrary\SimpleHelloEndPoint.php file)

This end point exposes these resources:

GET /
it will print on browser 'Hello to everybody'. Try it.
GET /<name>
it will print on browser 'Hello to <name>'.  Try it.
GET /botk
it will print on browser 'Thank you!!!''.  Try it.
POST /botk
it will print on browser 'Thank you posting me!!!'

structured_helloworld.php

Like reusable_helloword but the code is more complex and splitted in serveral files ( in mylibrary\HelloEndPoint directory)

This end point exposes these resources:

GET /about
shows a data structured structure. Try it.
GET /about/version
shows an attribute of about data structure . Try it.
GET /about?process=sum
shows a dinamic method od a data structure. Try it.
ANY /<name>
supports GET,POST,PUT,DELETE,OPTIONS,HEAD methods) Try it using an REST client

structured_helloworld.php

This example shows a simple application that mounts two reusable end-points:
  • the first is attached to resource '/hi' and provides  same resources in reusable_helloworld.php example;
  • the second is attached to resource '/hello' and provides  same resourcesin structured_helloworld.php example;
For example
  •   /hi/enrico
  •   /hi/botk (supports GET & POST http Method)
  •   /hello/about (supports content management)
  •   .. see other options in structured_helloworld.php example
Note that the 'hello' end-point supports content negotiation, while 'hi' does not: 'hello' end-point recognizes following media requests: 'text/html', 'text/plain', 'application/json', 'application/x-php', 'text/x-php' . Default media representation is 'text/html'.