Code Monkey home page Code Monkey logo

book-api's Introduction

Building

It is best to use the python virtualenv tool to build locally:

$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python manage.py migrate
$ python manage.py runserver

Then visit http://localhost:8000 to view the app.

To run tests :

$ python manage.py test

Then the endpoint:

GET http://localhost:8080/api/external-books?name=:nameOfABook

is requested, your application should query the Ice And Fire API and use the data received to respond with precisely the following JSON if there are results:

[
    "status_code": 200,
    "status": "success",
    "data": [
        {
            "name": "A Game of Thrones",
            "isbn": "978-0553103540",
            "authors": [
                "George R. R. Martin"
            ],
            "number_of_pages": 694,
            "publisher": "Bantam Books",
            "country": "United States",
            "release_date": "1996-08-01",
        },
        {
            "name": "A Clash of Kings",
            "isbn": "978-0553108033",
            "authors": [
                "George R. R. Martin"
            ],
            "number_of_pages": 768,
            "publisher": "Bantam Books",
            "country": "United States",
            "release_date": "1999-02-02",
        }
    ]
]

or precisely this JSON if the Ice and Fire API returns no results:

{
    "status_code": 200,
    "status": "success",
    "data": []
}

where :nameOfABook is a variable. Example value for :nameOfABook can be A Game Of Thrones. Note that the JSON property names that Ice And Fire uses don't quite match the ones in the required output that your application needs to deliver, so pay attention to this. Also, not all of the output from Ice And Fire is required in your application's output - you may need to suppress some field(s).

Create

When the endpoint:

POST http://localhost:8080/api/v1/books

is requested with the following data:

name
isbn
authors
country
number_of_pages
publisher
release_date

a book should be created in the local database and the following response should be returned:

[
    "status_code": 201,
    "status": "success",
    "data": [
        "book": {
            "name": "My First Book",
            "isbn": "123-3213243567",
            "authors": [
                "John Doe"
            ],
            "number_of_pages": 350,
            "publisher": "Acme Books",
            "country": "United States",
            "release_date": "2019-08-01",
        },
    ]
]

Read

When the endpoint:

GET http://localhost:8080/api/v1/books

is requested, your solution will return a list of books from the local database using the following response:

[
    "status_code": 200,
    "status": "success",
    "data": [
        {
            "id": 1,
            "name": "A Game of Thrones",
            "isbn": "978-0553103540",
            "authors": [
                "George R. R. Martin"
            ],
            "number_of_pages": 694,
            "publisher": "Bantam Books",
            "country": "United States",
            "release_date": "1996-08-01",
        },
        {
            "id": 2,
            "name": "A Clash of Kings",
            "isbn": "978-0553108033",
            "author": [
                "George R. R. Martin"
            ],
            "number_of_pages": 768,
            "publisher": "Bantam Books",
            "country": "United States",
            "release_date": "1999-02-02",
        }
    ]
]

or precisely this JSON if the Books API returns no results:

{
    "status_code": 200,
    "status": "success",
    "data": []
}

The Books API should be searchable by name (string), country (string), publisher (string) and release date (year, integer).

Update When the endpoint:

PATCH http://localhost:8080/api/v1/books/:id

is requested with any of the following form data:

name
isbn
authors
country
number_of_pages
publisher
release_date

and a specific :id in the URL, where :id is a place holder variable for an integer (for example 1), the specific book should be updated in the database and the following response should be returned:

[
    "status_code": 200,
    "status": "success",
    "message": "The book My First Book was updated successfully",
    "data": {
        "id": 1,
        "name": "My First Updated Book",
        "isbn": "123-3213243567",
        "authors": [
            "John Doe"
        ],
        "number_of_pages": 350,
        "publisher": "Acme Books Publishing",
        "country": "United States",
        "release_date": "2019-01-01",
    }
]

Delete

When the endpoint:

DELETE http://localhost:8080/api/v1/books/:id

is requested with a specific :id in the URL, where :id is a placeholder variable for an integer (for example 1), the specific book should be deleted from the database and the following response will be returned:

[
    "status_code": 204,
    "status": "success",
    "message": "The book My First Book was deleted successfully",
    "data": []
]

Show

When the endpoint:

GET http://localhost:8080/api/v1/books/:id

is requested with a specific :id in the URL, where :id is a placeholder variable for an integer (for example 1), it should show the specific book and the following response will be returned:

[
    "status_code": 200,
    "status": "success",
    "data": {
        "id": 1,
        "name": "My First Book",
        "isbn": "123-3213243567",
        "authors": [
            "John Doe"
        ],
        "number_of_pages": 350,
        "publisher": "Acme Books Publishing",
        "country": "United States",
        "release_date": "2019-01-01",
    }
]

book-api's People

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.