Skip to content

Mo8Faiz/Basics-of-RESTAPIs-in-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎬 Movie API

A simple RESTful API built with Spring Boot and MySQL to manage a collection of movies. Supports CRUD operations: Create, Read, Update, Delete, along with partial updates using PATCH.

🛠️ Technologies Used

Backend: Java 21, Spring Boot, Spring Data JPA

Database: MySQL

Build Tool: Maven

HTTP Client (for testing): Postman

⚡ Features

POST /api/movies → Add a new movie

GET /api/movies → Retrieve all movies

GET /api/movies/{id} → Retrieve a single movie by ID

PUT /api/movies/{id} → Replace an existing movie

PATCH /api/movies/{id} → Update specific fields of a movie

DELETE /api/movies/{id} → Remove a movie

🏗️ Project Setup

  1. Clone the repository
git clone https://github.com/Mo8Faiz/Basics-of-RESTAPIs-in-Java.git
cd Basics-of-RESTAPIs-in-Java
  1. Configure MySQL

Create a database:

CREATE DATABASE restapi;

Update application.properties (or application.yml) with your MySQL credentials:

spring.datasource.url=jdbc:mysql://localhost:3306/restapi
spring.datasource.username=root
spring.datasource.password=yourpassword
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

ddl-auto=update will create the movies table automatically from your entity class.

  1. Run the application
mvn spring-boot:run

Server will start at http://localhost:8080.

📦 API Usage Create a Movie POST :

http://localhost:8080/api/movies

Content-Type: application/json

{
  "title": "Dune",
  "director": "Denis Villeneuve",
  "year": 2021
}

Get All Movies GET :

http://localhost:8080/api/movies

Get Movie by ID GET :

http://localhost:8080/api/movies/2

Update Movie (Full) PUT :

http://localhost:8080/api/movies/{id}

Content-Type: application/json

{
  "title": "Dune 2",
  "director": "Denis Villeneuve",
  "year": 2023
}

Update Movie (Partial) PATCH :

http://localhost:8080/api/movies/{id}

Content-Type: application/json

{
  "year": 2023
}

Delete Movie DELETE :

http://localhost:8080/api/movies/{id}

🔧 Testing

Use Postman or any HTTP client.

Understand

The API is loosely coupled, so it can be consumed by frontends, mobile apps, or other services.

Ensure MySQL is running before starting the Spring Boot app.

The table movies is auto-generated from the Movie entity.

👤 Author

Md Faiz / Mo8Faiz

About

This is for my personal understanding of REST APIs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages