Web API
Due: 11:00pm, Friday April 16, 2021
Max grace days: 2
Description
The goal for this assignment is to make a web API using Sqlite and PHP. This assignment contains the following files: students.db
and students.php
. You need to edit the students.php
file.
We would like to make an API with “pretty URLs” like this:
GET /student
– return all recordsGET /student/{id}
– return a specific recordPOST /person
– create a new record from JSON dataPUT /person/{id}
– update an existing record from JSON dataDELETE /person/{id}
– delete an existing record
However, due to limitations with the current server setup we cannot. We will “fake it” with the following URLs instead where {}
indicates a placeholder value:
students.php?method=GET
return all records:
HTTP/1.1 200 OK Content-Type: application/json body: JSON array
students.php?method=GET&id={}
return a specific record:
HTTP/1.1 200 OK Content-Type: application/json body: JSON object
students.php?method=POST&id={}&first_name={}&last_name={}&gpa={}
create a new record:
HTTP/1.1 201 Created
students.php?method=PUT&id={}&first_name={}&last_name={}&gpa={}
update an existing record:
HTTP/1.1 200 OK
students.php?method=DELETE&id={}
delete an existing record:
HTTP/1.1 200 OK
If the id value is not valid for certain operations (GET, PUT, DELETE), then the response should be:
HTTP/1.1 404 Not Found
For this assignment, we will not worry about validating the input. However if data is missing for the for the create (POST) or update (PUT) operations, then the response should be something like:
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{"error": "Invalid input"}
The HTTP headers can be set in PHP with the header
function.
Note: The students.db
file and the directory it is in must have write permissions in order for the Apache server to write to the file. To enable write permissions, execute the following two commands from within the assignment directory:
chmod go+w students.db
chmod go+w .
Turning in the Assignment
For this assignment, you must turn in a zip file containing the following files:
students.php
Submit the zip file to the appropriate folder on D2L.
Grading Criteria
Grading (out of 100 points):
- 10 points – Documentation
- 10 – complete documentation that follows the standards
- 5 points – incomplete documentation and/or documentation that does not follow the standards
- 0 points – no documentation
- 45 points – PDO database operation
- 45 points – correct implementation with prepared statements
- 30 points – partially correct implementation
- 0 points – incorrect implementation
- 45 points – API responses
- 45 points – correct implementation
- 30 points – partially correct implementation
- 0 points – incorrect implementation