Project APIFor purposes of this API description, all URLs are relative to the base url of http://localhost:8080/delectable Also, all data is in JSON format. A GET request will return JSON. A PUT or POST will submit a JSON document. To keep things simple, no authentication is required to access any resource. MenuGET /menuReturns an array of all menu items in the menu. HTTP response code: 200 (OK). Resource URL/menu ParametersNone. Example RequestGET http://localhost:8080/delectable/menu Example Response[{ "id": 123, "name": "Lasagna", "price_per_person": 2.49, "minimum_order": 6, "categories": [{ "name": "organic" }, { "name": "vegetarian" }] }, { "id": 124, "name": "Buffalo Wings", "price_per_person": 1.75, "minimum_order": 12, "categories": [] }] GET /menu/{mid}Returns a detailed description of the menu item identified by {mid}. HTTP response code: 200 (OK), 404 (Not Found) if {mid} not found or invalid. Resource URL/menu/{mid} ParametersNone. Example RequestGET http://localhost:8080/delectable/menu/123 Example Response{ "id": 123, "name": "Lasagna", "price_per_person": 2.49, "minimum_order": 6, "categories": [{ "name": "organic" }, { "name": "vegetarian" }], "create_date": "20160229", "last_modified_date": "20160301" } OrderGET /orderReturns an array of all orders. HTTP response code: 200 (OK). Resource URL/order ParametersNone. Example RequestGET http://localhost:8080/delectable/order Example Response[{ "id": 456, "order_date": "20160229", "delivery_date": "20160301", "amount": 61.92, "surcharge": 0, "status": "open", "ordered_by": "virgil@example.com" }, { "id": 463, "order_date": "20160229", "delivery_date": "20160302", "amount": 63, "surcharge": 0, "status": "cancelled", "ordered_by": "bob@example.com" }] GET /order?date=YYYYMMDDReturns an array of all orders that need to be delivered on YYYYMMDD. HTTP response code: 200 (OK). Resource URL/order?date=YYYYMMDD ParametersNone. Example RequestGET http://localhost:8080/delectable/order?date=20160301 Example Response[{ "id": 456, "order_date": "20160229", "delivery_date": "20160301", "amount": 61.92, "surcharge": 0, "status": "open", "ordered_by": "virgil@example.com" }] PUT /orderCreates an order and returns the ID of that order {oid}. HTTP response codes: 201 (Created), 'Location' header with link to /order/{oid}. The body of the response will contain the order id, and the URL needed to cancel the order. Resource URL/order Parametersdelivery_date (required): date when order needs to be delivered. delivery_address (required): address where order needs to be delivered. personal_info (required): personal information for the person who places the order. note (required): can be empty. order_detail (required): a non-empty array of menu items. Example RequestPUT http://localhost:8080/delectable/order Here is data being PUT { "delivery_date": "20160301", "delivery_address": "10 West 31st ST, Chicago IL 60616", "personal_info": { "name": "Virgil B", "email": "virgil@example.com", "phone": "312-456-7890" }, "note": "Room SB-214", "order_detail": [{ "id": 123, "count": 8 }, { "id": 124, "count": 24 }] } Example Response{ "id": 456, "cancel_url": "/order/cancel/456" } GET /order/{oid}Returns the detail for the order identified by {oid}. HTTP response code: 200 (OK) or 404 (Not Found) if the order {oid} doesn't exist. Resource URL/order/{oid} ParametersNone. Example RequestGET http://localhost:8080/delectable/order/456 Example Response{ "id": 456, "amount": 61.92, "surcharge": 0, "status": "open", "order_date": "20160229", "delivery_date": "20160301", "ordered_by": { "name": "Virgil B", "email": "virgil@example.com", "phone": "312-456-7890" }, "delivery_address": "10 West 31st ST, Chicago IL 60616", "note": "Room SB-214", "order_detail": [{ "id": 123, "name": "Lasagna", "count": 8 }, { "id": 124, "name": "Buffalo Wings", "count": 24 }] } POST /order/cancel/{oid}Cancels the order identified by {oid}. HTTP response codes: 204 (No Content), 'Location' header with link to /order/{oid}. The body of the response will be empty. Resource URL/order/cancel/{oid} Parametersid (required): the ID of the order being cancelled. Example RequestPOST http://localhost:8080/delectable/order/cancel/456 Here is data being POST-ed { "id": 456 } CustomerGET /customerReturns an array of all customers that have placed an order in the system. HTTP response code: 200 (OK). Resource URL/customer ParametersNone. Example RequestGET http://localhost:8080/delectable/customer Example Response[{ "id": 701, "name": "Virgil B", "email": "virgil@example.com", "phone": "312-456-7890" }, { "id": 713, "name": "Bob Sample", "email": "bob@example.com", "phone": "312-456-7098" }] GET /customer?key=query_stringReturns an array of all customers that have placed an order in the system and match the query_string. An empty array will be returned if no customer matches the query_string. HTTP response code: 200 (OK). Resource URL/customer Parameterskey (optional): query string (aka keyword) used for search, if none specified, then everything matches. Example RequestGET http://localhost:8080/delectable/customer?key=sample Example Response[{ "id": 713, "name": "Bob Sample", "email": "bob@example.com", "phone": "312-456-7098" }] GET /customer/{cid}Returns details about customer identified by {cid}, including an array of all orders by that customer. HTTP response code: 200 (OK) or 404 (Not Found) if customer {cid} doesn't exist. Resource URL/customer/{cid} ParametersNone. Example RequestGET http://localhost:8080/delectable/customer/701 Example Response{ "id": 701, "name": "Virgil B", "email": "virgil@example.com", "phone": "312-456-7890", "orders": [{ "id": 456, "order_date": "20160229", "delivery_date": "20160301", "amount": 61.92, "surcharge": 0, "status": "open" }] } ReportGET /reportReturns an array of report IDs with their corresponding names. HTTP response code: 200 (OK). Resource URL/report ParametersNone. Example RequestGET http://localhost:8080/delectable/report Example Response[{ "id": 801, "name": "Orders to deliver today" }, { "id": 802, "name": "Orders to deliver tomorrow" }, { "id": 803, "name": "Revenue report" }, { "id": 804, "name": "Orders delivery report" }] GET /report/{rid}[?start_date=YYYYMMDD&end_date=YYYYMMDD]Returns the report identified by {rid}. If a start_date and end_date are provided, then use those to narrow the result set. HTTP response code: 200 (OK) or 404 (Not Found) if {rid} is invalid. Resource URL/report/{rid} Parametersstart_date (optional): the start date for the date range of the report. end_date (optional): the end date for the date range of the report. Example RequestGET http://localhost:8080/delectable/report/801 Example Response{ "id": 801, "name": "Orders to deliver today", "orders": [{ "id": 456, "amount": 61.92, "surcharge": 0, "status": "open", "order_date": "20160229", "delivery_date": "20160301", "ordered_by": { "name": "Virgil B", "email": "virgil@example.com", "phone": "312-456-7890" }, "delivery_address": "10 West 31st ST, Chicago IL 60616", "note": "Room SB-214", "order_detail": [{ "id": 123, "name": "Lasagna", "count": 8 }, { "id": 124, "name": "Buffalo Wings", "count": 24 }] }, { "id": 459, "amount": 128.90, "status": "open", "surcharge": 0, "order_date": "20160228", "delivery_date": "20160301", "ordered_by": { "name": "John Doe", "email": "john.doe@example.com", "phone": "123-456-7890" }, "delivery_address": "123 Main ST, Chicago IL 60617", "note": "We need chopsticks", "order_detail": [{ "id": 127, "name": "Chicken fried rice", "count": 32 }] }] } Another Example RequestGET http://localhost:8080/delectable/report/803?start_date=20160101&end_date=20160331 Example Response{ "id": 803, "name": "Revenue report", "start_date": "20160101", "end_date": "20160331", "orders_placed": 47, "orders_cancelled": 2, "orders_open": 45, "food_revenue": 513.98, "surcharge_revenue": 15 } Admin
PUT /admin/menuCreates a new menu item entry in the menu. HTTP response codes: 201 (Created), 'Location' header with link to /menu/account/{mid} where {mid} is the newly assigned ID for the menu item. Resource URL/admin/menu Parametersname (required): the name of the menu item. price_per_person (required): the price of this menu item per person. minimum_order (required): minimum number of orders of this menu item. categories (required): an array of categories the menu item belongs to, e.g. "organic", "vegan", etc. Example RequestPOST http://localhost:8080/delectable/admin/menu Here is data being PUT { "name": "Lasagna", "price_per_person": 2.49, "minimum_order": 6, "categories": [{ "name": "organic" }, { "name": "vegetarian" }] } Example Response{ "id": 123 } POST /admin/menu/{mid}Modifies the price for the menu item identified by {mid}. HTTP response codes: 204 (No Content), 400 (Bad Request) if data is missing from the request or is malformed. 'Location' header with link to /menu/{mid}. The body of the response will be empty. Resource URL/admin/menu/{mid} Parametersid (required): the ID of the menu item that's being changed. price_per_person (required): the price of this menu item per person. Example RequestPOST http://localhost:8080/delectable/admin/menu/123 Here is data being POST-ed { "id": 123, "price_per_person": 3.99 } GET /admin/surchargeReturns an the current value of the surcharge. HTTP response code: 200 (OK). Resource URL/menu ParametersNone. Example RequestGET http://localhost:8080/delectable/admin/surcharge Example Response{ "surcharge": 5 } POST /admin/surchargeModifies the surcharge amount. HTTP response codes: 204 (No Content), 400 (Bad Request) if data is missing from the request or is malformed. 'Location' header with link to /admin/surcharge. The body of the response will be empty. Resource URL/admin/surcharge Parameterssurcharge (required): the new surcharge amount. Example RequestPOST http://localhost:8080/delectable/admin/surcharge Here is data being POST-ed { "surcharge": 5.00 } POST /admin/delivery/{oid}Modifies the status of order {oid} to "delivered". HTTP response codes: 204 (No Content), 404 (Not Found) if {oid} not found or invalid. 'Location' header with link to /order/{oid}. The body of the response will be empty. Resource URL/admin/delivery/{oid} Parametersid (required): the id of the order being updated. Example RequestPOST http://localhost:8080/delectable/admin/delivery/456 Here is data being POST-ed { "id": 456 }
$Id: project-api.html,v 1.7 2016/10/12 15:24:20 virgil Exp $ |