Skip to content

This project contains an API for a library, which is a service that keeps records of students borrowing books.

Notifications You must be signed in to change notification settings

abdulla98/library-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

library-api

This project contains an API for a library, which is a service that keeps records of students borrowing books.

In this service users can also create, read update and delete books, students and borrows.

Requirements for this project can be found in requirements.txt file.

Table of Contents

  1. Tools

  2. Dependencies

  3. Getting Started

  4. Database

  5. REST Endpoints

Tools

For running it is required you to have:

  • Python

  • Flask as your build tool

  • You can choose the IDE of your preference.

  • PostgreSQL or any other database application

Dependencies

It is required you to have these dependencies:

Getting Started

First, clone the project:

https://github.com/abdulla98/library-api.git

Second, configure the database.

Database

  1. Create a database.

  2. Add the credentials of the database to /library-api/api/model/Model.py.

The default credentials are:

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:root@localhost:5432/library"
db = SQLAlchemy(app)
migrate = Migrate(app, db)

After you configure the database the next thing you should do is to open your IDE and install all the listed dependecies. If everything goes fine, you should be able to run the project and see a page here.

REST Endpoints

Book Endpoints

Insert a new book

  • URL localhost:5000/book/save, METHOD = POST
{
  "book_authorId": 1,
  "name": "Don Quixote",
  "pagecount": 863
}

Get all books

  • URL localhost:5000/books, METHOD = GET

Get book by ID

  • URL localhost:5000/book/{id}, METHOD = GET

Delete a book

  • URL localhost:5000/book/delete/{id}, METHOD = DELETE

Update a book

  • URL localhost:5000/book/update/{id}, METHOD = PUT

Student Endpoints

Insert a new student

  • URL localhost:5000/student/save, METHOT = POST
{
	"name": "John Doe",
  "birthdate": "25/06/1998",
  "gender": "Male",
  "student_class": "CST"
}

Get all students

  • URL localhost:5000/students, METHOD = GET

Get student by ID

  • URL localhost:5000/student/{id}, METHOD = GET

Delete a student

  • URL localhost:5000/student/delete/{id}, METHOD = DELETE

Update a student

  • URL localhost:5000/student/update/{id}, METHOD = PUT

Borrow Endpoints

Insert a new borrow

  • URL localhost:5000/borrow/save, METHOT = POST
{
	"book_id": 1,
  "student_id": 1,
  "taken_date": 10/06/2020,
  "brought_date": 20/06/2020
}

Get all borrows

  • URL localhost:5000/borrows, METHOD = GET

Get borrow by ID

  • URL localhost:5000/borrow/{id}, METHOD = GET

Delete a borrow

  • URL localhost:5000/borrow/delete/{id}, METHOD = DELETE

Update a borrow

  • URL localhost:5000/borrow/update/{id}, METHOD = PUT
{
  "taken_date": 13/07/2020,
  "brought_date": 22/07/2020
}

Author Endpoints

Insert a new author

  • URL localhost:5000/author/save, METHOT = POST
{
	"name": "Miguel Servantes"
}

Get all authors

  • URL localhost:5000/authors, METHOD = GET

Get an author by ID

  • URL localhost:5000/author/{id}, METHOD = GET

Delete an author

  • URL localhost:5000/author/delete/{id}, METHOD = DELETE

Update an author

  • URL localhost:5000/author/update/{id}, METHOD = PUT

About

This project contains an API for a library, which is a service that keeps records of students borrowing books.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published