HOST: http://127.0.0.1:8000/api/
This is a simple API allowing consumers to view books and their ratings. This API also allows users add books and edit the books which they added.
This is the endpoint responsible for registering new users and authenticates the newly registered user
-
Request (application/json)
{ "name": "John Doe", "email": "[email protected]", "password": "password" }
-
Response 200 (application/json)
{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9yZWdpc3RlciIsImlhdCI6MTUzNzEyNTM3OSwiZXhwIjoxNTM3MTI4OTc5LCJuYmYiOjE1MzcxMjUzNzksImp0aSI6IkVEazJITXdwNkI0VnJHZ1QiLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.tXvV8WQNvWJU8fDlVkqKs3mj4BMg2zdGyKQEr1IK8CI", "token_type": "bearer", "expires_in": 3600 }
This is the endpoint that enables existing users login and get their access token.
-
Request (application/json)
{ "email": "[email protected]", "password": "password" }
-
Response 200 (application/json)
{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug", "token_type": "bearer", "expires_in": 3600 }
This endpoint displays all the books that are present in the database, it is paginated to show only 25 entries per page.
-
Response 200 (application/json)
{ "data": [ { "id": 1, "title": "Narnia", "description": "A book of Fairytales", "average_rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", "user": { "id": 1, "name": "John", "email": "[email protected]", "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, "ratings": [ { "id": 1, "user_id": 10, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, { "id": 1, "user_id": 54, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, ] }, { "id": 26, "title": "The Lion King", "description": "Simba, look what you have done", "average_rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", "user": { "id": 1, "name": "John", "email": "[email protected]", "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, "ratings": [ { "id": 1, "user_id": 19, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, { "id": 1, "user_id": 4, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, ] } ], "links": { "first": "http://127.0.0.1:8000/api/books?page=1", "last": "http://127.0.0.1:8000/api/books?page=1", "prev": null, "next": null }, "meta": { "current_page": 1, "from": 1, "last_page": 1, "path": "http://127.0.0.1:8000/api/books", "per_page": 25, "to": 2, "total":2 } }
You may add your own books using this action. It takes a JSON object containing a title and a description.
-
Request (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "title": "Girl Nextdoor", "description": "Neighborly secrets" }
-
-
Response 201 (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "data": { "id": 4, "title": "Girl Nextdoor", "description": "Neighborly secrets", "average_rating": null, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", "user": { "id": 1, "name": "John", "email": "[email protected]", "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, "ratings": [] } }
-
This endpoint would list the details of a single book such as the title, description, and all the ratings asscociated with the book. This can be achieved by adding the book id trailing the url.
-
Response 200 (application/json)
{ "data": [ { "id": 1, "title": "Narnia", "description": "A book of Fairytales", "average_rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", "user": { "id": 1, "name": "John", "email": "[email protected]", "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, "ratings": [ { "id": 1, "user_id": 10, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, { "id": 1, "user_id": 54, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, ] } }
This endpoint enables a user which added a book to edit the book, bare in mind that the title and descriptions are required fields with the token added as the authorization header.
-
Request (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "title": "Narnia", "description": "A book with fairytales" }
-
-
Response 200 (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "data": [ { "id": 1, "title": "Narnia", "description": "A book with fairytales", "average_rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", "user": { "id": 1, "name": "John", "email": "[email protected]", "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, "ratings": [ { "id": 1, "user_id": 10, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, { "id": 1, "user_id": 54, "rating": 5, "created_at": "2017-07-09 19:29:18", "updated_at": "2017-07-09 19:29:18", }, ] } }
-
Using the delete method with the book id trailing the url, the user which created the book would be able to delete the book.
-
Request (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
-
Response 200 (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
"Delete Successful"
-
This endpoint accepts only the value rating as an integer, alongside authorization headers for users
-
Request (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "rating": 5 }
-
-
Response 200 (application/json)
-
Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTUzNzEyNjI1NywiZXhwIjoxNTM3MTI5ODU3LCJuYmYiOjE1MzcxMjYyNTcsImp0aSI6IlpXeklpYXhwaTM1WFpsNVciLCJzdWIiOjIzLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.sK7m_JOd3odbQ27p8L2Q10P8BPuaCdltNnKsi4626ug
-
Body
{ "data": { "user_id": 14, "book_id": 1, "rating": 5, "created_at": "2018-09-16 15:55:13", "updated_at": "2018-09-16 15:55:13", "book": { "id": 1, "user_id": 12, "title": "Narnia", "description": "A book with fairytales", "created_at": "2018-07-09 19:29:18", "updated_at": "2018-09-16 13:48:06" } } }
-