go · postgresql · httprouter

ArestAPI🎬

A small REST API for managing movies, built in Go to actually understand how token auth, background jobs, and PostgreSQL work under the hood — not just how to call a library that does it for you.

Go 1.20+ PostgreSQL httprouter Stateful tokens Rate limited
$git clone github.com/zeeshangolang/arestapi
$go run ./cmd/api
> listening on :4000
01 · under the hood

How the auth actually works

Not JWT — something simpler, and easier to revoke. The server never stores a token it could hand back to an attacker.

Server generates
random bytes
→
Sent to client
plaintext token
meanwhile, server-side
Same token
plaintext token
→
SHA-256
hash only
🗄 database stores only the hash — the plaintext token exists nowhere but the client's hands
On every request, the client sends Authorization: Bearer <token>. The server hashes it again and looks for a match — same principle as a password check. Delete the row, and the token is dead instantly. No expiry logic, no denylist needed.
02 · capabilities

What it can do

Movies, fully managed

Add, view, update, and delete movie records through a clean JSON API.

Accounts with activation

Register a user, activate the account with a token sent by email, then log in.

Rate limiting

Requests are throttled per client, so the API can't be spammed into the ground.

Background email

Activation emails send in the background, so they never hold up the response.

Hashed, revocable tokens

Random tokens, hashed at rest — revoke access instantly by deleting a row.

Clean JSON, everywhere

Consistent, predictable response shapes across every endpoint.

03 · reference

Endpoints

Movies
GET /v1/movies Get all movies
POST /v1/movies auth Add a new movie
GET /v1/movies/:id auth Get one movie by ID
PATCH /v1/movies/:id auth Update a movie
DELETE /v1/movies/:id auth Delete a movie
Users & auth
POST /v1/users Register a new user
PUT /v1/users/activated Activate an account with a token
POST /v1/tokens/authentication Log in and get an auth token
Health check
GET /v1/healthcheck Check if the API is alive
04 · setup

Getting started

Needs Go 1.20+ and a PostgreSQL instance you can connect to, local or remote.

1

Clone the repo

git clone https://github.com/zeeshangolang/arestapi.git cd arestapi
2

Set up the database

Make sure PostgreSQL is running and you have a database ready. The schema lives in the migrations folder — copy it over and it's easy to follow.

3

Run it

go run ./cmd/api
4

That's it

The API is now running locally, ready to take requests.

05 · what's next

Roadmap

Still a work in progress — adding to it as I learn more.

Add tests
Pagination and filtering for movies
Dockerize it
Deploy it somewhere live