COMP 74 Assignment 1
Milestone 1
Setup
1.Make a copy of the Slim PHP TripAPI_Starter project located in the COMP 74/Assign1 academic share folder.
2.Open the project with NetBeans.
3.Right click the TripAPI_Starter project node and select Composer and then Install (no dev). This will install the Slim and Illuminate package dependencies. (If this step does not work, you probably need to set up Composer on your own computer. Follow the instructions at https://getcomposer.org/).
4.Review the code in index.php (API endpoints), and in Person.php and Trip.php (Eloquent models). The project currently defines some sample code for providing API endpoints (“/persons”,“/trips”, etc.) The“/trips”endpoint also includes some initial paging code. The models provide some sample code for retrieving data from the travel database.
Step 1
The sample code for this endpoint currently parses all of the URI components, and obtains the page number from the‘page’parameter. (If no‘page’parameter was sent with the request, the page number is assigned null.) The code also defines a‘link to self’URI (i.e. rebuilds the original URI from the parsed components.)
Based on the sample code, complete the pagination code for the“/trips”endpoint by defining links to the first, last, next, and previous pages. For example if the trip table has 15 pages and page 4 is requested, the following links should be defined:
first = http://localhost:8000/trips?p…
last = http://localhost:8000/trips?p…
prev = http://localhost:8000/trips?p…
next = http://localhost:8000/trips?p…
Modify the sample code so that it returns these values in the‘links’field of the result.
Add code to detect‘out of range’pages. (Note: The Trip model class includes a method to that returns the page count.)
Add code to include the item count in the result. The item count will be the same as the page count (i.e. 5) for all pages except the last one, in which case it will be in the range 1-4.
Test your code in the Chrome browser (or with Postman) to make sure that the correct data and metadata (i.e. links and page count) are returned.
Hand in
At the end of the Week 6 Lab (Feb 12th), zip your entire project for this milestone to a zip file named YourLastName.zip, and copy it to the COMP 74 drop box folder.
Milesone 2
Step 2
1.Make a copy of the A1 Client Starter project (from Academic share or BlackBoard). This project contains code that makes a basic ajax request to the“/trips”endpoint in the TripAPI.
2.Open and run the TripAPI project.
3.Open and run the A1 Client Starter project. Test the client application by clicking the GET button. A list of five trips should be displayed.
4.Based on the code in the A1 Client Starter create a test client for the TripAPI that you wrote for Milestone 1. Your client should include an interface that:
a.includes a table which displays the trips returned from the API,
b.uses the links (returned in the metadata) to allow the user to navigate backwards, forwards, to the start, and to the end of the trip data,
c.allows the user to request a specific page of trip data,
d.informs the user when a bad request is has been made (e.g. invalid page number). Note: this may require additional code in your TripAPI.
Hand in
At the end of the Week 7 Lab (Feb 21th), zip your entire project for this milestone to a zip file named YourLastName.zip, and copy it to the COMP 74 drop box folder.