Skip to content

SHabaj-dev/BookStore-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Bookstore Backend

This is a backend API for a bookstore, built with Go, Gorilla Mux for routing, and GORM for MySQL database interaction.

Features

  • Create a new book
  • Retrieve all books
  • Retrieve a book by its ID
  • Update a book by its ID
  • Delete a book by its ID

Prerequisites

  • Go 1.16+
  • MySQL
  • Git

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/go-bookstore-backend.git
    cd go-bookstore-backend
  2. Install dependencies:

    go mod tidy
  3. Set up MySQL database:

    • Create a database in MySQL.
    • Update the database connection details in your application configuration (e.g., config/config.go).
  4. Run the application:

    go run main.go

API Routes

The following routes are available in the API:

  • Create a new book

    • URL: /book/
    • Method: POST
    • Description: Creates a new book in the bookstore.
  • Retrieve all books

    • URL: /book/
    • Method: GET
    • Description: Retrieves all books in the bookstore.
  • Retrieve a book by ID

    • URL: /book/{bookId}
    • Method: GET
    • Description: Retrieves a book by its ID.
  • Update a book by ID

    • URL: /book/{bookId}
    • Method: PUT
    • Description: Updates a book by its ID.
  • Delete a book by ID

    • URL: /book/{bookId}
    • Method: DELETE
    • Description: Deletes a book by its ID.

Example Usage

Creating a new book

curl -X POST http://localhost:8080/book/ -d '{
  "Title": "The Catcher in the Rye",
  "Author": "J.D. Salinger",
  "Publisher": "Little, Brown and Company"
}'

Getting all books

curl http://localhost:8080/book/

Getting a book by ID

curl http://localhost:8080/book/1

Updating a book

curl -X PUT http://localhost:8080/book/1 -d '{
  "Title": "The Catcher in the Rye",
  "Author": "Jerome David Salinger",
  "Publisher": "Little, Brown and Company"
}'

Deleting a book

curl -X DELETE http://localhost:8080/book/1

Dependencies

  • Gorilla Mux: A powerful URL router and dispatcher for Golang.
  • GORM: The fantastic ORM library for Golang.
  • MySQL: The world's most popular open-source database.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

About

Simme Crud BookStore BAckend Using go-lang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages