Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Benja022/api-coding-task-fork

 
 

Repository files navigation

Lord of the Rings API

A RESTful API built with Slim Framework for managing characters and factions from the Lord of the Rings universe.

Features

  • Create and manage characters
  • Create and manage factions
  • Create and manage equipments
  • JSON-based API
  • Input validation
  • Duplicate checking for factions

Requirements

  • PHP 8.0 or higher
  • MySQL 5.7 or higher
  • Docker and Docker Compose
  • Composer (PHP package manager)

Installation

  1. Clone the repository:
git clone <repository-url>
cd api-coding-task-fork
  1. Build the project using the Makefile:
make build
  1. Start the Docker containers:
docker-compose up -d

or

docker-compose up
  1. Run the tests to verify everything is working:
make test
  1. (Optional) Generate API documentation:
make docs

Examples API Endpoints

This project include a postman file to try de endpoints generated, as JSON.

Characters

Create a Character

  • URL: /characters
  • Method: POST
  • Content-Type: application/json
  • Request Body:
{
  "name": "Aragorn",
  "birth_date": "2931-03-01",
  "kingdom": "Gondor",
  "equipment_id": 1,
  "faction_id": 1
}
  • Success Response:
    • Code: 201
    • Content:
{
  "id": 1,
  "message": "Character created successfully"
}

Factions

Create a Faction

  • URL: /factions
  • Method: POST
  • Content-Type: application/json
  • Request Body:
{
  "faction_name": "GONDOR",
  "description": "Gondor is the most powerful kingdom of men in Middle-earth"
}
  • Success Response:
    • Code: 201
    • Content:
{
  "id": 1,
  "message": "Faction created successfully"
}
  • Error Response (if faction already exists):
    • Code: 409
    • Content:
{
  "error": "A faction with this name already exists",
  "existing_faction": {
    "id": 1,
    "faction_name": "GONDOR",
    "description": "Gondor is the most powerful kingdom of men in Middle-earth"
  }
}

Get All Factions

  • URL: /factions
  • Method: GET
  • Success Response:
    • Code: 200
    • Content:
{
  "factions": [
    {
      "id": 1,
      "faction_name": "GONDOR",
      "description": "Gondor is the most powerful kingdom of men in Middle-earth"
    }
  ]
}

Error Responses

400 Bad Request

{
  "error": "Request body must be valid JSON"
}

or

{
  "error": "Missing required field: field_name"
}

500 Internal Server Error

{
  "error": "Failed to create faction",
  "message": "Error details"
}

Database Schema

Characters Table

  • id (int, primary key, auto-increment)
  • name (varchar(128))
  • birth_date (date)
  • kingdom (varchar(128))
  • equipment_id (int, foreign key)
  • faction_id (int, foreign key)

Factions Table

  • id (int, primary key, auto-increment)
  • faction_name (varchar(128))
  • description (text)

Equipments Table

  • id (int, primary key, auto-increment)
  • name (varchar(128))
  • type (varchar(128))
  • made_by (varchar(128))

About

This is the technical test project for API oriented backends

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 88.4%
  • PHP 9.7%
  • CSS 0.9%
  • JavaScript 0.8%
  • Makefile 0.1%
  • Shell 0.1%