Build a Movies API with PHP & MySQL with XAMPP
This project is the result of completing Udemy course PHP | Build a Complete API
- How to build a database with MySQL using XAMPP
- How to check database credentials to set up the connection
// database credendials
$db_name = "movies_api";
$mysql_username = "root";
$mysql_password = "";
$server_name = "127.0.0.1";
// connection variable ----> connect to database
$conn = mysqli_connect($server_name,$mysql_username,$mysql_password,$db_name);
- Creating endpoints to achieve:
- Get all movies from the database
HTTP Method: GET, Endpoint: get_all_movies.php
- Get a single movie from the database:
- Get a movie by id
HTTP Method: GET, Endpoint: get_movie.php?id={id}
- Get a movie by name (title)
HTTP Method: GET, Endpoint: get_movie.php?name={title}
- Update a movie already in the database
HTTP Method: POST, Endpoint: update_movie.php?id={id}
- Delete a movie from the database
HTTP Method: POST, Endpoint: delete_movie.php?id={id}
- Create/Insert a new movie to the database
HTTP Method: POST, Endpoint: create_movie.php
- Testing endpoints
- How to test the Create, Delete, and Update endpoints using test.html files
<form method="POST" action="http://localhost:8000/update_movie.php">
<input type="text" name="id" value="1"/>
<input type="text" name="storyline" value="test storyline"/>
<input type="text" name="box_office" value="5"/>
<input type="text" name="stars" value="8"/>
<input type="submit" value="submit" />
</form>
- Sending accurate Response Codes
$response[$response['response_code'] = 200 // request successful
$response['response_code'] = 201 // resource successfully created
$response['response_code'] = 204; // successful but no content to return (ex: delete movie)
- Documentation
- Importance of excellent documentation to ensure developers can connect to your API which includes providing all endpoints with examples of the request format
PHP | MySQL | XAMPP | HTML |
Beth Meeker GH |