Laravel Web Service

 

Service that navigates an imaginary robotic hoover through an imaginary room, built with Laravel for routing, application code and testing.

https://github.com/davidgrayston/room-service

Try out the demo here »

Web Service

OpenAPI Specification
Endpoint

Application Code

The classes that deal with moving the hoover around the room can be found in the App\RoomService namespace.

Request Log

All request inputs/outputs are logged using the ApiRequest model.

The log can be viewed at http://localhost:8080/log

Testing

Tests can be found in the tests directory.

Docker

Docker has been used to containerise the application.

  • Makefile provides useful commands to install/start/stop/test. 
  • Docker Compose defines the appweb and database services required to run the application. 

Code Examples

PHP (Guzzle)

$json_data = [
  'roomSize' => [5, 5],
  'coords' => [1, 2],
  'patches' => [
    [1, 0],
    [2, 2],
    [2, 3],
  ],
  'instructions' => 'NNESEESWNWW',
];

$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost:8080/api/']);

$response = $client->request('POST', 'room/hoover', [
  'json' => $json_data,
  'headers' => [
    'Accept' => 'application/json'
  ]
]);

echo $response->getBody();

curl

curl -X POST "http://localhost:8080/api/room/hoover" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"roomSize\":[5,5],\"coords\":[1,2],\"patches\":[[1,0],[2,2],[2,3]],\"instructions\":\"NNESEESWNWW\"}"