This program is a simple RESTful CRUD (Create, Read, Update, Delete) API using the Go programming language. It demonstrates how to build a basic API server with endpoints for managing a collection of books. The program uses the gorilla/mux package to handle HTTP routing and JSON encoding/decoding.
The tutorial for this program can be found at the following URL: https://www.youtube.com/watch?v=gIe543ufGmE
The source code can be found at: https://github.com/BorntoDev/CRUD-Golang/
- Create a new book
- Retrieve all books
- Retrieve a single book by ID
- Update a book by ID
- Delete a book by ID
To run this program, you will need to install the Gorilla Mux router package:
go get -u github.com/gorilla/mux
The program uses two main data structures:
- Book: Represents a book with the following fields:
- ID: Unique identifier for the book Isbn: International Standard Book Number
- Title: Title of the book
- Author: Pointer to the author struct
- Author: Represents an author with the following fields:
- Firstname: Author's first name
- Lastname: Author's last name
The API has the following endpoints:
GET /api/books
: Retrieve all booksGET /api/books/{id}
: Retrieve a single book by IDPOST /api/books
: Create a new bookPUT /api/books/{id}
: Update a book by IDDELETE /api/books/{id}
: Delete a book by ID
To run the program, execute the following command:
go run main.go
The API will start listening on port 8000.