title | keywords | description | ||||
---|---|---|---|---|---|---|
GORM |
|
Using GORM with SQLite database. |
This is a sample program demonstrating how to use GORM as an ORM to connect to a SQLite database with the Fiber web framework.
- Go 1.18 or higher
- Go modules
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/gorm-example
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
-
The server will start on
http://localhost:3000
.
Method | URL | Description |
---|---|---|
GET | /api/v1/book | Retrieves all books |
GET | /api/v1/book/:id | Retrieves a book by ID |
POST | /api/v1/book | Creates a new book |
DELETE | /api/v1/book/:id | Deletes a book |
curl -X GET http://localhost:3000/api/v1/book
curl -X GET http://localhost:3000/api/v1/book/1
curl -X POST http://localhost:3000/api/v1/book -d '{"title": "New Book", "author": "Author Name"}' -H "Content-Type: application/json"
curl -X DELETE http://localhost:3000/api/v1/book/1