Skip to content

MikolajRatajczyk/Langmal-Server-Go

Repository files navigation

Langmal-Server

Logo of Langmal backend project featuring a blue chinchilla sitting on a server.

Welcome to the backend service of the Langmal quiz app.
This project is written in Go and covered by unit tests.

Features

  • Register, login, and logout user using JWT.
  • Store and serve quiz results from a DB.
  • Provide a health check endpoint for monitoring.

Quick start ⚡️

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.

Config ⚙️

You may provide the full configuration by:

  1. Switching to the release mode
export GIN_MODE=release
  1. Setting the secret used for JWTs:
export LANGMAL_JWT_SECRET=YourSecret

Running the tests ✅

go test ./...

API 🔌

Endpoints marked with 🔐 require a JWT in Authorization header, example: Bearer yourJwt.

Register

  • endpoint: /user/register
  • method: POST
  • body:
    {
      "email": "foo@bar.com",
      "password": "password"
    }
  • example response:
    200
    
    {
      "message": "User has been registered."
    }

Log-in

  • endpoint: /user/login
  • method: POST
  • body:
    {
      "email": "foo@bar.com",
      "password": "password"
    }
  • example response:
    200
    
    {
      "jwt": "yourJwt"
    }

Log-out

  • endpoint: /user/logout
  • method: POST
  • body:
    {
      "token": "yourJwt"
    }
  • example response:
    200
    
    {
      "message": "Logged-out (token has been blocked)"
    }

Get quizzes 🔐

  • 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
          }
        ]
      }
    ]

Get results 🔐

  • 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 🌍"
      }
    ]

Save result 🔐

  • 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."
    }

Check health

  • endpoint: /health
  • method: GET
  • example response:
    200
    

About

Go backend of the Langmal quiz app

Topics

Resources

Stars

Watchers

Forks

Languages