students-api-go

module
v0.0.0-...-6a339a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2025 License: MIT

README ΒΆ

Go Version

πŸ§‘β€πŸŽ“ 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.

Directories ΒΆ

Path Synopsis
cmd
students-api command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL