Welcome to the backend service of the Langmal quiz app.
This project is written in Go and covered by unit tests.
- Register, login, and logout user using JWT.
- Store and serve quiz results from a DB.
- Provide a health check endpoint for monitoring.
git clone https://github.com/MikolajRatajczyk/Langmal-Server-Go.git
cd Langmal-Server-Go
go run main.go
The server should now be running at localhost:5001
.
You may provide the full configuration by:
- Switching to the release mode
export GIN_MODE=release
- Setting the secret used for JWTs:
export LANGMAL_JWT_SECRET=YourSecret
go test ./...
Endpoints marked with 🔐 require a JWT in Authorization
header, example: Bearer yourJwt
.
- endpoint:
/user/register
- method:
POST
- body:
{ "email": "foo@bar.com", "password": "password" }
- example response:
200
{ "message": "User has been registered." }
- endpoint:
/user/login
- method:
POST
- body:
{ "email": "foo@bar.com", "password": "password" }
- example response:
200
{ "jwt": "yourJwt" }
- endpoint:
/user/logout
- method:
POST
- body:
{ "token": "yourJwt" }
- example response:
200
{ "message": "Logged-out (token has been blocked)" }
- endpoint:
/content/quizzes
- method:
GET
- example response:
200
[ { "title": "Space and beyond 🚀", "id": "5e8ef788-f305-4ee3-ad69-ba8924ca3806", "questions": [ { "title": "Which planet is known as the \"Red Planet\" 🔴?", "options": [ "Jupiter", "Saturn", "Mars" ], "answer": 2 }, { "title": "What galaxy is Earth located in 🌌?", "options": [ "Andromeda", "Milky Way", "Large Magellanic Cloud" ], "answer": 1 } ] } ]
- endpoint:
/content/results
- method:
GET
- example response:
200
[ { "correct": 2, "wrong": 1, "quiz_id": "4e2778d3-57df-4fe9-83ec-afffec1ec5c", "created_at": 1729953525, "quiz_title": "Giants of the world 🌍" } ]
- endpoint:
/content/results
- method:
POST
- body:
{ "created_at": 1729953525, "wrong": 1, "quiz_id": "4e2778d3-57df-4fe9-83ec-afffec1ec5c", "correct": 2 }
- example response:
201
{ "message": "Result saved." }
- endpoint:
/health
- method:
GET
- example response:
200