Skip to content

fillahalfatih/go-restful-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Go RESTful API - Book Management

A simple RESTful API for managing book data using Golang, GORM, MySQL, and Gorilla Mux.

🚀 Features

  • ✅ Get all books
  • ✅ Get a book by ID
  • ✅ Create a new book
  • ✅ Update a book by ID
  • ✅ Delete a book by ID

🏗️ Tech Stack

⚙️ Project Structure


go-restful-api/
├── config/
│   └── db.go
├── handlers/
│   └── book_handler.go
├── models/
│   └── book.go
├── routes/
│   └── routes.go
├── .env
├── go.mod
├── LICENSE
├── main.go
└── README.md

🛠️ Setup and Run

1. Clone the Repository

git clone https://github.com/fillahalfatih/go-restful-api.git
cd go-restful-api

2. Setup .env

Create a .env file and fill in your database credentials:

DB_USER=root
DB_PASSWORD=
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=db_name

3. Install Dependencies

go mod tidy

4. Run the Server

go run main.go

The server will run at:

http://localhost:8080

📡 API Endpoints

Method Endpoint Description
GET /api/books Get all books
GET /api/books/{id} Get a book by ID
POST /api/books Add a new book
PUT /api/books/{id} Update a book by ID
DELETE /api/books/{id} Delete a book by ID

📝 Sample Request JSON

{
    "id": "a07e28fc-4b4f-4bf8-8fd7-72f9bd1235fc",
    "isbn": "448-1234567890",
    "title": "Book One",
    "year": 2025,
    "author_id": 2,
    "author": {
        "id": 2,
        "first_name": "Grant",
        "last_name": "Gustin"
    }
}

🧾 License

Free to use for learning and personal exploration.

About

A simple RESTful API for managing book data using Golang, GORM, MySQL, and Gorilla Mux.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages