Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Git
.git
.gitignore

# Maven
target/
!target/*.jar
.mvn/
mvnw
mvnw.cmd

# IDE files
.idea/
*.iml
.vscode/
*.swp
*.swo

# Logs
logs/
*.log

# OS specific
.DS_Store
Thumbs.db

# Docker
.dockerignore
docker-compose*.yml

# Documentation
README*.md
LICENSE
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM maven:3.8.6-openjdk-17-slim AS build
WORKDIR /app

# Copy the Maven POM file
COPY pom.xml .

# Copy the source code
COPY src ./src

# Build the application
RUN mvn clean package -DskipTests

# Create the runtime image
FROM openjdk:17-slim
WORKDIR /app

# Copy the JAR file from the build stage
COPY --from=build /app/target/*.jar app.jar

# Environment variables
ENV MYSQL_HOST=mysql \
MYSQL_PORT=3306 \
MYSQL_DATABASE=restapi \
MYSQL_USER=root \
MYSQL_PASSWORD=password \
SERVER_PORT=8080

# Expose the port the app runs on
EXPOSE ${SERVER_PORT}

# Command to run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
123 changes: 104 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,121 @@
# REST API

![REST API](https://img.shields.io/badge/REST_API-v1.0-blue)
[![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.3.2-brightgreen)](https://spring.io/projects/spring-boot)
[![Java](https://img.shields.io/badge/Java-17-orange)](https://www.java.com/)
[![MySQL](https://img.shields.io/badge/MySQL-8.0-blue)](https://www.mysql.com/)
[![Maven](https://img.shields.io/badge/Maven-3.8.6-red)](https://maven.apache.org/)
[![Docker](https://img.shields.io/badge/Docker-Ready-blue)](https://www.docker.com/)
[![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)

## Deskripsi
## Description

REST API ini adalah aplikasi yang dirancang untuk menyediakan antarmuka pemrograman aplikasi (API) yang mengikuti prinsip REST. API ini memungkinkan pengguna untuk melakukan operasi dasar seperti **CRUD (Create, Read, Update, Delete)** untuk data tertentu.
This REST API is a robust application designed to provide a RESTful interface following industry best practices. Built with Spring Boot, it offers a comprehensive solution for performing CRUD (Create, Read, Update, Delete) operations on data resources. The API is designed with scalability, security, and ease of use in mind.

## Fitur
## Features

- **Pengelolaan Data**: Buat, baca, perbarui, dan hapus data.
- **Autentikasi Pengguna**: Sistem autentikasi sederhana untuk keamanan API.
- **Response Format**: Menggunakan format JSON untuk semua response.
- **Penggunaan yang Mudah**: Dokumentasi lengkap dan contoh penggunaan.
- **Complete CRUD Operations**: Create, read, update, and delete data with well-defined endpoints
- **RESTful Architecture**: Follows REST principles for predictable and standardized API behavior
- **JSON Response Format**: All API responses are formatted in JSON for easy integration
- **Error Handling**: Comprehensive error handling with appropriate HTTP status codes
- **Data Validation**: Input validation to ensure data integrity
- **User Authentication**: Secure endpoints with authentication mechanisms
- **API Documentation**: Detailed documentation for all endpoints
- **Docker Support**: Easy deployment with Docker containers

## Teknologi yang Digunakan
## Technologies Used

- **Bahasa Pemrograman**: [Java](https://www.java.com/)
- **Framework**: [Spring Boot](https://spring.io/projects/spring-boot)
- **Database**: [MySQL](https://www.mysql.com/)
- **Dependency Management**: [Maven](https://maven.apache.org/)
- **Programming Language**: [Java 17](https://www.java.com/)
- **Framework**: [Spring Boot 3.3.2](https://spring.io/projects/spring-boot)
- **Database**: [MySQL 8.0](https://www.mysql.com/)
- **ORM**: [Spring Data JPA](https://spring.io/projects/spring-data-jpa)
- **Build Tool**: [Maven](https://maven.apache.org/)
- **Containerization**: [Docker](https://www.docker.com/)

## Prerequisites

Sebelum menjalankan aplikasi, pastikan Anda memiliki:
Before running the application, ensure you have:

- Java JDK 17 atau yang lebih baru
- MySQL Server
- Maven
- Java JDK 17 or newer
- MySQL Server 8.0 or newer
- Maven 3.6+ (or use the included Maven wrapper)
- Docker and Docker Compose (for containerized deployment)

## Instalasi
## Installation

1. **Clone Repositori**
### Option 1: Standard Installation

1. **Clone the Repository**
```bash
git clone https://github.com/yourbee03/REST_API.git
cd REST_API
```

2. **Configure Database**

Update the database configuration in `src/main/resources/application.properties` with your MySQL credentials.

3. **Build the Application**
```bash
./mvnw clean install
```

4. **Run the Application**
```bash
./mvnw spring-boot:run
```

### Option 2: Docker Installation

1. **Clone the Repository**
```bash
git clone https://github.com/yourbee03/REST_API.git
cd REST_API
```

2. **Build and Run with Docker Compose**
```bash
docker compose up -d
```

This will start both the Spring Boot application and a MySQL database in containers.

## API Endpoints

The API provides the following endpoints:

- `GET /api/resource` - Retrieve all resources
- `GET /api/resource/{id}` - Retrieve a specific resource
- `POST /api/resource` - Create a new resource
- `PUT /api/resource/{id}` - Update an existing resource
- `DELETE /api/resource/{id}` - Delete a resource

## Environment Variables

When using Docker, you can configure the application using the following environment variables:

- `MYSQL_HOST` - MySQL database host
- `MYSQL_PORT` - MySQL database port
- `MYSQL_DATABASE` - MySQL database name
- `MYSQL_USER` - MySQL username
- `MYSQL_PASSWORD` - MySQL password
- `SERVER_PORT` - Application server port

## Testing

Run the automated tests with:

```bash
./mvnw test
```

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the LICENSE file for details.
38 changes: 0 additions & 38 deletions README_ENG.md

This file was deleted.

47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.8'

services:
# Spring Boot Application
app:
build:
context: .
dockerfile: Dockerfile
container_name: rest-api-app
ports:
- "8080:8080"
environment:
- MYSQL_HOST=mysql
- MYSQL_PORT=3306
- MYSQL_DATABASE=restapi
- MYSQL_USER=root
- MYSQL_PASSWORD=password
- SERVER_PORT=8080
depends_on:
- mysql
networks:
- rest-api-network
restart: unless-stopped

# MySQL Database
mysql:
image: mysql:8.0
container_name: rest-api-mysql
ports:
- "3306:3306"
environment:
- MYSQL_DATABASE=restapi
- MYSQL_ROOT_PASSWORD=password
volumes:
- mysql-data:/var/lib/mysql
networks:
- rest-api-network
restart: unless-stopped
command: --default-authentication-plugin=mysql_native_password

networks:
rest-api-network:
driver: bridge

volumes:
mysql-data:
driver: local
15 changes: 15 additions & 0 deletions docker-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Build and start the Docker containers
echo "Building and starting Docker containers..."
docker-compose up -d --build

# Check if containers are running
echo "Checking container status..."
docker-compose ps

echo ""
echo "REST API is now running!"
echo "Access the API at: http://localhost:8080/api"
echo ""
echo "To stop the containers, run: docker-compose down"
9 changes: 9 additions & 0 deletions docker-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Stop and remove Docker containers
echo "Stopping Docker containers..."
docker-compose down

echo ""
echo "Docker containers have been stopped."
echo "To start the containers again, run: ./docker-start.sh"