Code Monkey home page Code Monkey logo

bookshelf-api's Introduction

Bookshelf-API

WebApp to track reading activities

  1. API dapat menampilkan semua buku

Kriteria

  • Method : GET
  • URL : /books

Response Server

  • Server harus mengembalikan response
    • status code : 200
    • response body :
{
    "status": "success",
    "data": {
        "books": [
            {
                "id": "Qbax5Oy7L8WKf74l",
                "name": "Buku A",
                "publisher": "Dicoding Indonesia"
            },
            {
                "id": "1L7ZtDUFeGs7VlEt",
                "name": "Buku B",
                "publisher": "Dicoding Indonesia"
            },
            {
                "id": "K8DZbfI-t3LrY7lD",
                "name": "Buku C",
                "publisher": "Dicoding Indonesia"
            }
        ]
    }
}
  1. API dapat menampilkan detail buku

Kriteria

  • Method : GET
  • URL : \books{bookid}

Bila buku dengan id yang dilampirkan pada client tidak ditemukan, maka server merespon dengan

  • Status code : 404
  • Response Body :
{
    "status": "fail",
    "message": "Buku tidak ditemukan"
}

Bila buku dengan id terlampir,

  • Status code : 200
  • Response body:
{
    "status": "success",
    "data": {
        "book": {
            "id": "aWZBUW3JN_VBE-9I",
            "name": "Buku A Revisi",
            "year": 2011,
            "author": "Jane Doe",
            "summary": "Lorem Dolor sit Amet",
            "publisher": "Dicoding",
            "pageCount": 200,
            "readPage": 26,
            "finished": false,
            "reading": false,
            "insertedAt": "2021-03-05T06:14:28.930Z",
            "updatedAt": "2021-03-05T06:14:30.718Z"
        }
    }
}
  1. API dapat menyimpan buku

Kriteria

Request Client

API menyimpan buku pada route

  • Method : POST
  • URL : /books
  • Body Request
{
    "name": string,
    "year": number,
    "author": string,
    "summary": string,
    "publisher": string,
    "pageCount": number,
    "readPage": number,
    "reading": boolean
}

Objek buku yang disimpan pada server

{
    "id": "Qbax5Oy7L8WKf74l",
    "name": "Buku A",
    "year": 2010,
    "author": "John Doe",
    "summary": "Lorem ipsum dolor sit amet",
    "publisher": "Dicoding Indonesia",
    "pageCount": 100,
    "readPage": 25,
    "finished": false,
    "reading": false,
    "insertedAt": "2021-03-04T09:11:44.598Z",
    "updatedAt": "2021-03-04T09:11:44.598Z"
}

Keterangan

  • id bernilai unik. Dapat menggunakan nanoid
  • finished properti boolean yang menentukan apakah buku sudah selesai dibaca. finished didapatkan dari observasi pageCount === readPage
  • insertedAt merupakan properti tanggal dimasukannya buku. Dapat menggunakan method Date.toISOString()
  • updatedAt merupakan properti menampung tanggal diperbarui buku. Awal masuk, sama dengan insertedAt

Respon Server

Server merespon gagal jika

  • Client tidak melampirkanname pada request body. Maka
    • Status Code : 400
    • Response body
{
	status: 'fail',
	message: "Gagal menambahkan buku. Mohon isi nama buku"
}
  • Client melampirkan properti readPage yang lebih besar daripada pageCount
    • Status code = 400
    • Response body
{
	status: 'fail',
	message: "Gagal menambahkan buku. readPage tidak boleh lebih besar dari pageCount"
}
  • server gagal memasukkan buku karena alasan umum, maka server merespon dengan
    • status code : 500
    • response body
{
    "status": "error",
    "message": "Buku gagal ditambahkan"
}

Bila buku berhasil ditambahkan

  • Status code 200
  • response body
{
    "status": "success",
    "message": "Buku berhasil ditambahkan",
    "data": {
        "bookId": "1L7ZtDUFeGs7VlEt"
    }
}
  1. API dapat menghapus buku

Kriteria

Menghapus book berdasarkan id yang diberikan

  • Method : DELETE
  • URL : /books/{bookid}

Bila id tidak ditemukan maka

  • Status code : 404
  • Response body :
{
    "status": "fail",
    "message": "Buku gagal dihapus. Id tidak ditemukan"
}

Bila id ditemukan, maka

  • Status code : 200
  • Response body
{
    "status": "success",
    "message": "Buku berhasil dihapus"
}
  1. API dapat mengubah data buku

Kriteria

Harus mengubah data buku berdasarkan id

  • Method : PUT
  • URL : /books/{bookid}
  • Body Request :
{
    "name": string,
    "year": number,
    "author": string,
    "summary": string,
    "publisher": string,
    "pageCount": number,
    "readPage": number,
    "reading": boolean
}

Response Server

Server harus merespon gagal jika :

  • Client tidak melampirkanname pada request body. Maka
    • Status Code : 400
    • Response body
{
	status: 'fail',
	message: "Gagal memperbarui buku. Mohon isi nama buku"
}
  • Client melampirkan properti readPage yang lebih besar daripada pageCount
    • Status code = 400
    • Response body
{
	status: 'fail',
	message: "Gagal menambahkan buku. readPage tidak boleh lebih besar dari pageCount"
}
  • Bila id tidak dapat ditemukan
    • Status code : 404;
    • Response body
{
    "status": "fail",
    "message": "Gagal memperbarui buku. Id tidak ditemukan"
}

bila buku berhasil diperbarui

  • Status code : 200
  • Response body
{
    "status": "success",
    "message": "Buku berhasil diperbarui"
}

Keterangan : Jika belum ada buku yang dimasukkan kembalikan array books kosong

bookshelf-api's People

Contributors

adityap1502 avatar

Watchers

 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.