Giter VIP home page Giter VIP logo

bookshop's Introduction

bookshop

bookshop REST API example

Requirements

  • PHP 5.5+

installation

$ git clone https://github.com/JaroslavKrenar/bookshop.git
$ php composer.phar install

Configuration

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

Usage

$ php -S localhost:8000 server.php

Test suite

The test suite is run via phpunit.

To run the unit tests: phpunit

API

Please specify "accept" header field to decide what type of content should be response.

Supported headers:

"application/json" - JSON request and response

GET /api/v1/search

Parameters
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

Example

$ http://localhost:8000/api/v1/search?release_date=2005-07-04
Response
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"
    }
  ]
}

POST /api/v1/add-book

Parameters
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

Example

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"
}
Response
Status: 200 OK

{
  "id": 1000
}
Error response
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."
    ]
  }
}

bookshop's People

Contributors

jaroslavkrenar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.