1

## Hello World Example PHP >= 5.4

basic

Basic hello world example to get started with Restler 5.

> This API Server is made using the following php files/folders

> - index.php (gateway)
> - Say.php (api)
> - restler.php (framework)
> - JsonFormat.php (format)

This API Server exposes the following URIs

    GET say/hello ⇠ Say::hello()
    GET say/hi    ⇠ Say::hi()

> Note:- If you have used Restler 2 before, you will wonder why the generated routes are lesser with Restler 5. Look at Routes example to understand.

Try the following links in your browser

GET say/hello

      "Hello world!"

GET say/hello?to=R.Arul%20Kumaran

      "Hello R.Arul Kumaran!"

GET say/hi?to=restler3.1

      "Hi restler3.1!"

If the above links fail, it could be due to missing `.htaccess` file or URL Rewriting is not supported in your server. If you are on Apache Server, make sure `AllowOverride` is set to `All` instead of `None` in the `httpd.conf` file.

In case you could not get URL Rewriting to work, try the following links instead

GET index.php/say/hello

      "Hello world!"

GET index.php/say/hello?to=R.Arul%20Kumaran

      "Hello R.Arul Kumaran!"

GET index.php/say/hi?to=restler3.1

      "Hi restler3.1!"

We expect the following behaviour from this example.

    @example1 @helloworld
    Feature: Testing Helloworld Example

      Scenario: Saying Hello world
        When I request "examples/_001_helloworld/say/hello"
        Then the response status code should be 200
        And the response is JSON
        And the type is "string"
        And the value equals "Hello world!"

      Scenario: Saying Hello Restler
        Given that "to" is set to "Restler"
        When I request "examples/_001_helloworld/say/hello{?to}"
        Then the response status code should be 200
        And the response is JSON
        And the type is "string"
        And the value equals "Hello Restler!"

      Scenario: Saying
        When I request "examples/_001_helloworld/say"
        Then the response status code should be 404
        And the response is JSON
        And the type is "array"

      Scenario: Saying Hi
        When I request "examples/_001_helloworld/say/hi"
        Then the response status code should be 400
        And the response is JSON
        And the type is "array"

      Scenario: Saying Hi Arul
        Given that "to" is set to "Arul"
        When I request "examples/_001_helloworld/say/hi{?to}"
        Then the response status code should be 200
        And the response is JSON
        And the type is "string"
        And the value equals "Hi Arul!"

It can be tested by running the following command on terminal/command line from the project root (where the vendor folder resides). Make sure `base_url` in `behat.yml` is updated according to your web server.

    vendor/bin/behat  features/examples/_001_helloworld.feature