bookshop REST API example
- PHP 5.5+
$ git clone https://github.com/JaroslavKrenar/bookshop.git
$ php composer.phar install
You can configure database connection in config/database.php
(mysql
is selected as default) and create tables with the following command:
$ php artisan migrate
$ php artisan key:generate
$ php -S localhost:8000 server.php
The test suite is run via phpunit.
To run the unit tests: phpunit
Please specify "accept"
header field to decide what type of content should be response.
Supported headers:
"application/json"
- JSON request and response
Name | Type | Description |
---|---|---|
isbn | string | ISBN |
author | string | Author name |
title | string | Book title |
release_date | string | Release data. You can use ```" |
minimum_rating | float | Search by minimum rating |
$ http://localhost:8000/api/v1/search?release_date=2005-07-04
Status: 200 OK
{
"count": 1,
"books": [
{
"ID": 2,
"isbn": "9784115709669",
"author": "Velda Keeling Jr.",
"title": "Hatter. 'Nor I,' said the Mock Turtle Soup is.",
"rating": "9.99",
"release_date": "2005-07-04",
"created_at": "2016-07-04 10:01:59",
"updated_at": "2016-07-04 10:01:59"
}
]
}
Name | Type | Description |
---|---|---|
isbn | string | ISBN |
author | string | Author name |
title | string | Book title |
rating | float | Book rating |
release_date | string | Release data in format Y-m-d |
Request
$ http://localhost:8000/api/v1/add-book
{
'isbn' => "9780833052643"
'author' => "Pascale Lesch"
'title' => "WILL do next! If they had to fall a long way. So."
'rating' => 3.44
'release_date' => "2016-01-23"
}
Status: 200 OK
{
"id": 1000
}
Status: 500 Internal Server Error
{
"message": "Invalid input data",
"code": 500,
"type": "ValidationException",
"data": {
"isbn": [
"The isbn field is required."
],
"author": [
"The author field is required."
],
"title": [
"The title field is required."
],
"rating": [
"The rating field is required."
],
"release_date": [
"The release date field is required."
]
}
}