burger

Тask

Реализовать WEB API для взаимодействия с БД, где хранятся данные о фильмах + CRUD операции с ней,плюс метод вывода фильма определённого жанра. Фильм: название, студия разработчик, несколько жанров, которым соответствует фильм. SOLID MVC MVVM.

CRUD REST API with MySQL & PHP PDO

This project show you how to create a simple CRUD RESTful API with MySQL database. Fronted side are build using AJAX technique allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. Backend side uses PHP's PDO for database access.

schem of project

Backend PHP DataBase

You can add new records in the database, edit them and delete. Try it now.
Backend part have a few limitation such as quantity of records and autorefreshing (every 20 minutes) the database with the data by default. So new records you are made are not store in the DB constantly.

Show DB.
Keep in mind that the DB is refreshing every 20 minutes.

Refresh DB. Set DB data by default.

refresh DB Are you sure?

All PHP file codes used in this project are available by clicking the button.

show PHP codes

1. Get All

Get a list of videogames

GET
/api/read.php

2. Read (Get Single Row)

Getting one videogame by its id.

GET
/api/single_read.php?id=1
show post request

{
   "id": "1"
}     
                  

The form below is to send GET request with id. Write an id you want and click the button to see result.

Read single row

3. Create

Create a new videogame.

POST
/api/create.php
show example post request

{
   "name": "Combat",
   "game_producer": "Sony",
   "category": "Horror"
}     
                  

Add new videogame in the Database and don't forget fill all fields correctly. Quantity of rows has limitation in 12 records.

Create new

4. Update/Edit

Updating always has required to provide the id of data.

POST
/api/update.php
show example post request

{
   "id": "1",
   "name": "Combat",
   "game_producer": "Sony",
   "category": "Horror"
}     
                  

There is the form to send POST request with updated values. Choose row from the table you want to edit by clicking "insert data in form". After that edit fields with new data and click "update" to see result.

id name game_producer category
1 DOOM Apple Shooters
2 Warcraft Google Real-time strategy
3 Age of Empires Nintendo Real-time strategy
4 Crash Bandicoot Sega Platformer
5 Forza Motorsport Xbox Simulation
6 Gears of War Bandai Shooters
7 Portal 2 Casio Puzzlers
8 The Long Dark Sony Survival and horror

5. Delete

Delete one videogame identified by its id.

POST
/api/delete.php
show example post request
                  
{
   "id": "1"
}     
                  
               

You are free to delete any existing row from database. Click the button "delete" to see result.

Delete

6. Search

Searching by category

GET
/api/search.php?search=category
POST
/api/search.php
show post request

{
   "search": "category"
}     
                  

There are two forms to send request with id. Write an id you want and click the button to see result.

Search games by category (POST)

AJAX request (json)

Search games by category (GET)

Submit, reload the page
X

DB data

id name game_producer category