A simple and clean RESTful API built with Go and SQLite, designed to manage students using full CRUD operations. Great for beginners learning Go's modular project layout, routing, SQLite, and input validation.
GitHub Repo 👉 github.com/ashunasar/golang-students-crud-api
students-api/
├── cmd/
│ └── students-api/ # Main entry point (main.go)
├── config/
│ └── local.yaml # App config
├── internal/
│ ├── config/ # Loads config (cleanenv)
│ ├── http/handlers/student/ # All student API handlers
│ ├── models/ # Student model definitions
│ ├── storage/ # Storage interface + SQLite impl
│ └── utils/response/ # Response formatting & validation errors
├── storage/
│ └── storage.db # SQLite DB file
├── go.mod
├── go.sum
├── README.md
└── students-api.postman_collection.json # Postman collection for testing
env: 'dev'
storage_path: 'storage/storage.db'
http_server:
address: 'localhost:8082'git clone https://github.com/ashunasar/golang-students-crud-api.git
cd golang-students-crud-api
go mod tidyThe project uses the Go SQLite3 driver:
go get github.com/mattn/go-sqlite3go run cmd/students-api/main.go -config config/local.yamlThis will:
- Load config
- Open SQLite DB (
storage.db) - Register HTTP routes
- Start server at
localhost:8082
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/student |
Create a student |
| GET | /api/students |
Get all students |
| GET | /api/students/{id} |
Get student by ID |
| PUT | /api/students |
Update student |
| DELETE | /api/students/{id} |
Delete student |
POST /api/student
{
"name": "hello",
"email": "example@xample.com",
"Age": 18
}GET /api/students
GET /api/students/1
PUT /api/students
{
"id": 1,
"name": "updated name",
"email": "hello2@xample.com",
"Age": 19
}DELETE /api/students/1
- 🐹 Go
- 🗓 SQLite
- 📌
github.com/mattn/go-sqlite3for SQLite driver - 📦 go-playground/validator for validation
- 📘 cleanenv for config
- 📡 Native
net/http - 📄 JSON REST API
All responses follow this standard:
{
"status": "OK",
"data": {
"id": 1,
"name": "John"
}
}{
"status": "Error",
"error": "student not found"
}- Logging is handled using Go’s
slog - Routes are handled manually with
http.NewServeMux - SQLite storage is modular and implements an interface
- Validations use tags like
validate:"required,email"
Use the provided file:
students-api.postman_collection.json
You can import this into Postman to test all API routes quickly.
- Add pagination
- Add search/filter by name or email
- Add Swagger or Redoc API docs
- Dockerize the application
- Add unit tests
Created by ashunasar Feel free to ⭐️ star the repo, fork it, and contribute!