3Shoka / Spring-Boot-Rest-API-Books

Spring-Boot-Rest-API-Books

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring-Boot-Rest-API-Books

Spring-Boot-Rest-API-Books

To run this project please follow the instructions below :

mvn clean spring-boot:run

It is simple Spring Boot Rest service CRUD operation example using MySQL database.

  1. Import project in Netbeans (recommended), Eclipse/Spring STS as Maven Project.

  2. Run project as Spring Boot Application or deploy it on Tomcat or any Application Server.

  3. Open your terminal and run this command : mvn clean spring-boot:run

No need to create DB. It creates automatically by Spring Boot.

  1. Execute SQL Files to insert data into your MySQL Database.

  2. Open Postman rest client or other rest client.

  3. Set Content type as application/json.

List API's :

  1. Show All Books :

Get Request

URL: http://localhost:8080/api/buku

Method: GET

[
  {
    "bookId": "B001",
    "title": "30 Hari Mencari Cinta",
    "category": "Novel",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B002",
    "title": "30 Hari Mencari Jodoh",
    "category": "Novel",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B003",
    "title": "30 Hari Mencari Rezeki",
    "category": "Novel",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B004",
    "title": "30 Hari Mahir Java",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B005",
    "title": "30 Hari Mahir PHP",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B006",
    "title": "30 Hari Mahir C++",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 1,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B007",
    "title": "30 Hari Mahir C++",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 2,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B008",
    "title": "30 Hari Mahir C++",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 3,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B009",
    "title": "30 Hari Mahir Java",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 2,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B010",
    "title": "30 Hari Mahir Java",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 3,
    "available": 0,
    "peminjaman": []
  },
  {
    "bookId": "B011",
    "title": "30 Hari Mahir C++",
    "category": "Pemrograman",
    "registered": "2016-09-04",
    "total": 4,
    "available": 0,
    "peminjaman": []
  }
]
  1. Get Post Request to Add Book

URL: http://localhost:8080/api/buku

Method: POST

{
      "bookId": "B011",
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman"
}
  1. Filter the Book Collections :

URL: http://localhost:8080/api/buku/filter/title/category

Method : POST

Request :

{     
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman"
}

Reponse :


{
  "Payload": [
    {
      "bookId": "B006",
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman",
      "registered": "2016-09-04",
      "total": 1,
      "available": 0,
      "peminjaman": []
    },
    {
      "bookId": "B007",
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman",
      "registered": "2016-09-04",
      "total": 2,
      "available": 0,
      "peminjaman": []
    },
    {
      "bookId": "B008",
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman",
      "registered": "2016-09-04",
      "total": 3,
      "available": 0,
      "peminjaman": []
    },
    {
      "bookId": "B011",
      "title": "30 Hari Mahir C++",
      "category": "Pemrograman",
      "registered": "2016-09-04",
      "total": 4,
      "available": 0,
      "peminjaman": []
    }
  ],
  "message": "Buku ditemukan!",
  "Success": "True"
}
  1. Add New Borrower :

Method : POST


http://localhost:8080/api/peminjam

{
      "uid": "U008",
      "name" : "Namikaze Minato",
      "address" : "Konohagakure"
     
}
  1. Add Transaction

Method Post :

URL : http://localhost:8080/api/peminjaman2

Request :


{
     
      "bookId": "B003",
      "userId" : "U003"
}

Response :


{
  "Payload": {
    "id": 6,
    "startDt": "2016-09-04",
    "returnDt": "2016-09-13",
    "bookId": "B003",
    "userId": "U003"
  },
  "message": "Data Peminjaman sukses",
  "Success": "True"
}
  1. See History Transaction :

Method : POST

URL : http://localhost:8080/api/peminjaman2/find

Request :


{     
      "bookId": "B003",
      "userId" : "U003"
}

Response :


{
  "Payload": [
    {
      "id": 1,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B002",
      "userId": "U002"
    },
    {
      "id": 2,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B002",
      "userId": "U001"
    },
    {
      "id": 3,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B002",
      "userId": "U003"
    },
    {
      "id": 4,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B003",
      "userId": "U003"
    },
    {
      "id": 5,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B003",
      "userId": "U003"
    },
    {
      "id": 6,
      "startDt": "2016-09-04",
      "returnDt": "2016-09-13",
      "bookId": "B003",
      "userId": "U003"
    }
  ],
  "message": "Data Peminjaman berhasil ditemukan",
  "Success": "True"
}

About

Spring-Boot-Rest-API-Books


Languages

Language:Java 72.2%Language:Shell 16.3%Language:Batchfile 11.5%