Skip to content

thrtn85/library-mgmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library Management API Documentation

Overview

The Library Management API provides endpoints to manage a collection of books and users. It allows you to create, retrieve, update, and delete books and users. The API uses JSON for data exchange and is built using Go, Gin, and GORM with SQLite as the database.

Base URL

http://localhost:1111

Endpoints

Books

  • Create a Book

    • URL: /books

    • Method: POST

    • Description: Creates a new book.

    • Request Body:

      {
        "title": "string",
        "author": "string"
      }
    • Response:

      {
        "id": "int",
        "title": "string",
        "author": "string",
        "created_at": "timestamp",
        "updated_at": "timestamp"
      }
    • Example:

      curl -X POST -H "Content-Type: application/json" -d "{\"title\":\"The Go Programming Language\", \"author\":\"Alan A. A. Donovan\"}" http://localhost:1111/books
  • Retrieve All Books

    • URL: /books

    • Method: GET

    • Description: Retrieves a list of all books.

    • Response:

      [
        {
          "id": "int",
          "title": "string",
          "author": "string",
          "created_at": "timestamp",
          "updated_at": "timestamp"
        }
      ]
    • Example:

      curl http://localhost:1111/books
  • Retrieve a Specific Book

    • URL: /books/:id

    • Method: GET

    • Description: Retrieves a specific book.

    • Response:

      [
        {
          "id": "int",
          "title": "string",
          "author": "string",
          "created_at": "timestamp",
          "updated_at": "timestamp"
        }
      ]
    • Example:

      curl http://localhost:1111/books/2
  • Update a Book

    • URL: /books/:id

    • Method: PUT

    • Description: Updates an existing book by ID.

    • Request Body:

      {
        "title": "string",
        "author": "string"
      }
    • Response:

      {
        "id": "int",
        "title": "string",
        "author": "string",
        "created_at": "timestamp",
        "updated_at": "timestamp"
      }
    • Example:

      curl -X PUT -H "Content-Type: application/json" -d "{\"title\":\"Updated Title\", \"author\":\"Updated Author\"}" http://localhost:1111/books/1
  • Delete a Book

    • URL: /books/:id

    • Method: DELETE

    • Description: Deletes an existing book by ID.

    • Response:

      {
        "message": "Book deleted successfully"
      }
    • Example:

      curl -X DELETE http://localhost:1111/books/1

Users

  • Create a User

    • URL: /users

    • Method: POST

    • Description: Creates a new user.

    • Request Body:

      {
        "name": "string",
        "email": "string",
        "password": "string"
      }
    • Response:

      {
        "id": "int",
        "name": "string",
        "email": "string",
        "created_at": "timestamp",
        "updated_at": "timestamp"
      }
    • Example:

      curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"John Doe\", \"email\":\"john@example.com\", \"password\":\"password\"}" http://localhost:1111/users
  • Retrieve All Users

    • URL: /users

    • Method: GET

    • Description: Retrieves a list of all users.

    • Response:

      [
        {
          "id": "int",
          "name": "string",
          "email": "string",
          "created_at": "timestamp",
          "updated_at": "timestamp"
        }
      ]
    • Example:

      curl http://localhost:1111/users
  • Retrieve a Specific User

    • URL: /users/:id

    • Method: GET

    • Description: Retrieves a specific user.

    • Response:

      [
        {
          "id": "int",
          "name": "string",
          "email": "string",
          "created_at": "timestamp",
          "updated_at": "timestamp"
        }
      ]
    • Example:

      curl http://localhost:1111/users/1
  • Update a User

    • URL: /users/:id

    • Method: PUT

    • Description: Updates an existing user by ID.

    • Request Body:

      {
        "name": "string",
        "email": "string"
      }
    • Response:

      {
        "id": "int",
        "name": "string",
        "email": "string",
        "created_at": "timestamp",
        "updated_at": "timestamp"
      }
    • Example:

      curl -X PUT -H "Content-Type: application/json" -d "{\"name\":\"Updated Name\", \"email\":\"updated@example.com\"}" http://localhost:1111/users/1
  • Delete a User

    • URL: /users/:id

    • Method: DELETE

    • Description: Deletes an existing user by ID.

    • Response:

      {
        "message": "User deleted successfully"
      }
    • Example:

      curl -X DELETE http://localhost:1111/users/1

Error Handling

All endpoints will return appropriate HTTP status codes and error messages in case of failures. Here are some common error responses:

  • 400 Bad Request: The request data is invalid or malformed.
  • 404 Not Found: The requested resource was not found.
  • 500 Internal Server Error: An error occurred on the server.

Models

Book

  • ID: int
  • Title: string
  • Author: string
  • CreatedAt: timestamp
  • UpdatedAt: timestamp

User

  • ID: int
  • Name: string
  • Email: string
  • Password: string (hashed)
  • CreatedAt: timestamp
  • UpdatedAt: timestamp

Example Requests

Create a Book

curl -X POST -H "Content-Type: application/json" -d "{\"title\":\"The Go Programming Language\", \"author\":\"Alan A. A. Donovan\"}" http://localhost:1111/books

Retrieve All Books

curl http://localhost:1111/books

Retrieve a Specific Book

curl http://localhost:1111/books/1

Update a Book

curl -X PUT -H "Content-Type: application/json" -d "{\"title\":\"Updated Title\", \"author\":\"Updated Author\"}" http://localhost:1111/books/1

Delete a Book

curl -X DELETE http://localhost:1111/books/1

Create a User

curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"John Doe\", \"email\":\"john@example.com\", \"password\":\"password\"}" http://localhost:1111/users

Retrieve All Users

curl http://localhost:1111/users

Retrieve a Specific User

curl http://localhost:1111/users/1

Update a User

curl -X PUT -H "Content-Type: application/json" -d "{\"name\":\"Updated Name\", \"email\":\"updated@example.com\"}" http://localhost:1111/users/1

Delete a User

curl -X DELETE http://localhost:1111/users/1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages