Web API

Based on simple REST principles, the lab169 API endpoints return JSON metadata about brand, model, os, screensize and image directly from the Phones database.

Request

The lab169 API is based on REST principles. Data resources are accessed via standard HTTP requests in UTF-8 format to an API endpoint.
The API makes use of CRUD Functionality which implies the following actions:

Method Action Path
GET Retrieves Products in database /api/retrieve
POST Creates Products in database /api/create
PUT Updates Products within database /api/update
DELETE Deletes Products in database /api/delete

The URI for each Method contains the scheme and authority of the URI -> "http://localhost:3000" + the path to which each Method corresponds

Parameters with each Method

There are 6 Parameters in total to control the API (not each method needs every parameter) but they do each have there own requirement and description.

Method Parameters needed Example
GET None OR Id OR Brand OR Model OR (Model AND Brand) GET Method with no Parameters retrieves all products within database
POST ALL Parameters Needed (apart from id, which the api creates upon POSTing) POST Method with: {brand:"Apple",model:"Iphone 6",os: "iOS",image: URL,screensize: 8},
creates an id (e.g id=2) corresponding with the data of the JSON object
PUT ALL Parameters needed; Id is locator, the rest you can change PUT Method with existing id can change all data within that JSON object.
e.g. Instead of in the above example the model being Iphone 7 it could instead be Iphone 6 with screensize 7
DELETE Only Parameter of id is needed If you wanted to delete your created Object, giving the DELETE Method
the parameters "Id" with an id in the database would delete that product.
In our example giving the json data id=2 would get rid of the now Iphone 6

Response Status Code

Our Web API responses all include a JSON Object with MIME Type 'application/json'.
With each response there is a corresponding Status Code:

Status Code Description
200 OK - The request has succeeded. The client can read the result of the request in the body and the headers of the response.
201 Created - The request has been fulfilled and resulted in a new resource being created.
304 Not Modified - Data already exist within the Database
400 Bad Request - The request could not be understood by the server due to malformed syntax. The message body will contain more information.
403 Forbidden - The server understood the request, but is refusing to fulfill it.
404 Not Found - The requested resource could not be found. This error can be due to a temporary or permanent condition.The message body will contain more information.
500 Internal Server Error. You should never receive this error ,whilst your API is running because our clever coders catch them all …