
π§βπ Students-api
A lightweight and modular RESTful API in Go to manage student records using SQLite. Built with clean architecture, structured logging, and input validation.
π Features
- β Create new students (
POST)
- π Get all students (
GET)
- βοΈ Update student info (
PUT)
- β Delete a student (
DELETE)
- β
Input validation using
go-playground/validator
- π¦ Persistent storage using SQLite
- βοΈ Configurable via YAML
- π§± Clean folder structure with interfaces
π οΈ Tech Stack
- Go 1.21+
- SQLite via
mattn/go-sqlite3
- HTTP Server using
net/http
- Structured Logging using
log/slog
- Input Validation using
go-playground/validator
- YAML Configuration
π Folder Structure
students-api-go/
βββ cmd/
β βββ students-api/ # Entry point
β βββ main.go
βββ config/
β βββ local.yaml # App configuration
βββ internal/
β βββ config/ # Config loader
β βββ http/
β β βββ handlers/
β β βββ student/ # API handler
β βββ storage/
β β βββ sqlite/ # SQLite driver
β β βββ storage.go # Interface (future-proofing)
β βββ types/ # Domain types
β βββ utils/response/ # Standard response writer
βββ storage/
β βββ storage.db # SQLite DB file (auto-created)
βββ go.mod
βββ go.sum
βοΈ Configuration
config/local.yaml:
env: "dev"
storage_path: "storage/storage.db"
http_server:
address: "localhost:8082"
π How to Run
1. Clone the repo
git clone https://github.com/Ashank007/students-api-go.git
cd students-api-go
2. Run the app
CONFIG_PATH=config/local.yaml go run cmd/students-api/main.go
βΉοΈ The server will start at http://localhost:8082
The SQLite database is auto-created at storage/storage.db
π‘ API Reference
πΉ POST /api/students
Create a new student record.
πΈ Request Body
{
"name": "John",
"email": "john@example.com",
"age": 21
}
πΈ Response
{
"id": 1
}
πΉ GET /api/students
Fetch all students
πΈ Response
[
{
"id": 1,
"name": "John",
"email": "John@example.com",
"age": 21
}
]
π§ͺ Sample curl Commands
Create a new student
curl -X POST http://localhost:8082/api/students \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"John@example.com","age":21}'
Get all students
curl http://localhost:8082/api/students
Update student
curl -X PUT http://localhost:8082/api/students \
-H "Content-Type: application/json" \
-d '{"id":1,"name":"Updated Name","email":"updated@mail.com","age":23}'
Delete student
curl -X DELETE "http://localhost:8082/api/students?id=1"
π Validation Rules
Field Rule
name required
email required
age required
π§ Future Enhancements
-
Add support for pagination
-
Add GET /api/students/{id} for single record
-
Swagger/OpenAPI auto docs
-
Dockerfile for containerization
-
CI pipeline via GitHub Actions
πͺͺ License
This project is licensed under the MIT License.