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.
http://localhost:1111
-
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
-
-
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\":\"[email protected]\", \"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\":\"[email protected]\"}" 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
-
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.
- ID:
int
- Title:
string
- Author:
string
- CreatedAt:
timestamp
- UpdatedAt:
timestamp
- ID:
int
- Name:
string
- Email:
string
- Password:
string
(hashed) - CreatedAt:
timestamp
- UpdatedAt:
timestamp
curl -X POST -H "Content-Type: application/json" -d "{\"title\":\"The Go Programming Language\", \"author\":\"Alan A. A. Donovan\"}" http://localhost:1111/books
curl http://localhost:1111/books
curl http://localhost:1111/books/1
curl -X PUT -H "Content-Type: application/json" -d "{\"title\":\"Updated Title\", \"author\":\"Updated Author\"}" http://localhost:1111/books/1
curl -X DELETE http://localhost:1111/books/1
curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"John Doe\", \"email\":\"[email protected]\", \"password\":\"password\"}" http://localhost:1111/users
curl http://localhost:1111/users
curl http://localhost:1111/users/1
curl -X PUT -H "Content-Type: application/json" -d "{\"name\":\"Updated Name\", \"email\":\"[email protected]\"}" http://localhost:1111/users/1
curl -X DELETE http://localhost:1111/users/1