Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Users API

A simple Users API built with Go's standard library — no frameworks, no external dependencies. Built as a learning project to understand HTTP servers, middleware, and concurrency in Go.

Overview

Full CRUD API for managing users, built entirely with Go's net/http package. Uses an in-memory store with sync.RWMutex for safe concurrent access, a logger middleware that tracks request duration, email validation and duplicate detection, and graceful shutdown on SIGINT/SIGTERM.

API Endpoints

Create a user

POST /users

Body:

{
  "name": "John Doe",
  "email": "john@example.com"
}

Response: 201 Created

{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "created_at": "2026-02-25T13:00:00Z"
}

Get all users

GET /users

Response: 200 OK

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com",
    "created_at": "2026-02-25T13:00:00Z"
  }
]

Get a user by ID

GET /users/{id}

Response: 200 OK or 404 Not Found


Update a user

PATCH /users/{id}

Body: (all fields optional)

{
  "name": "Jane Doe",
  "email": "jane@example.com"
}

Response: 200 OK with updated user


Delete a user

DELETE /users/{id}

Response: 204 No Content


Error responses

All errors return a JSON body:

{
  "error": "user not found"
}

Common error codes: 400 Bad Request, 404 Not Found, 409 Conflict

Project Structure

users-api/
├── main.go       # Everything lives here — handlers, middleware, server setup
└── go.mod        # Module definition

Since this is a learning project, everything is intentionally kept in a single file for readability. A production version would split handlers, middleware, and the store into separate packages.

About

A simple REST API for managing users, built with Go's standard library. No frameworks, no external dependencies.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages