A RESTful API built with Slim Framework for managing characters and factions from the Lord of the Rings universe.
- Create and manage characters
- Create and manage factions
- Create and manage equipments
- JSON-based API
- Input validation
- Duplicate checking for factions
- PHP 8.0 or higher
- MySQL 5.7 or higher
- Docker and Docker Compose
- Composer (PHP package manager)
- Clone the repository:
git clone <repository-url>
cd api-coding-task-fork- Build the project using the Makefile:
make build- Start the Docker containers:
docker-compose up -dor
docker-compose up- Run the tests to verify everything is working:
make test- (Optional) Generate API documentation:
make docsThis project include a postman file to try de endpoints generated, as JSON.
- 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"
}- 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"
}
}- 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": "Request body must be valid JSON"
}or
{
"error": "Missing required field: field_name"
}{
"error": "Failed to create faction",
"message": "Error details"
}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)
id(int, primary key, auto-increment)faction_name(varchar(128))description(text)
id(int, primary key, auto-increment)name(varchar(128))type(varchar(128))made_by(varchar(128))