Project APIFor purposes of this API description, all URLs are relative to the base url of http://localhost:8080/lf2u 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. All use cases marked with [*] are not required as part of the final delivery for this project. The following abbreviations are used throughout this document:
Farmers
POST /farmersCreates an account and returns (in the body of the response) the ID of the account. 'Location' header with link to /farmers/{fid} where {fid} is the newly assigned ID for the farmer account. HTTP response code: 201 (Created) if everything is ok. 400 (Bad Request) if any of the required data is missing or is invalid. Resource URL/farmers Parametersfarm_info: Information about the farm
personal_info: Contact information for the farmer
delivers_to (required): Zip codes the farm delivers to Example Request
Here is data being POST-ed
Example Response
PUT /farmers/{fid}Updates the account identified by {fid}. The payload of the request replaces the existing account. HTTP response code: 200 (OK). The body of the response will be empty. If the account identified by {fid} doesn't exist, then the HTTP response code will be 404 (Not Found). Resource URL/farmers/{fid} Parametersfarm_info: Information about the farm
personal_info: Contact information for the farmer
delivers_to (required): Zip codes the farm delivers to Example Request
Here is data being PUT.
Example ResponseThe body of the response is empty. GET /farmers/{fid}Returns detailed information about the farm account identified by {fid}. HTTP response code: 200 (OK) or 404 (Not found) if the account identified by {fid} doesn't exist. Resource URL/farmers/{fid} ParametersNone. Example Request
Example Response
GET /farmers[?zip=ddddd]Returns an array of farmers that have accounts with LF2U. If the zip parameter is specified then only return those farmers that deliver in the zip code. HTTP response code: 200 (OK). Resource URL/farmers[?zip=ddddd] Parameterszip (optional): five digits Example Request
Example Response
GET /farmers/{fid}/productsReturns an array of all products in the store identified by the farmer ID {fid}. HTTP response code: 200 (OK) if {fid} is valid, 404 (Not Found) otherwise. Resource URL/farmers/{fid}/products ParametersNone Example Request
Example Response
POST /farmers/{fid}/productsAdds product from the general (LF2U) catalog to the farmer store identified by {fid}. The body of the response will contain the ID of the product entry in farmer's store. 'Location' header with link to /farmers/{fid}/products/{fspid} where {fspid} is the newly assigned ID for the the product in farmer's store. HTTP response code: 201 (Created). Resource URL/farmers/{fid}/products Parametersgcpid (required): the ID of the generic product in the general (LF2U) catalog. note (optional): a personal description of the product; will be displayed next to the general catalog product name when the customer looks at farmer's store. start_date (optional): date of the year, e.g. "MM-DD" when the product becomes available; if not specified then the product is available starting with the first day of the year. end_date (optional): date of the year, e.g. "MM-DD" when the product is last available; if not specified, then the product is available through the last day of the year. price (required): price per unit of product. product_unit (required): what is the unit for which the price is defined, e.g. "lb", "floz", "Kg", etc. image (optional): URL for the picture of this store product. Example Request
Here is data being POST-ed
Example Response
POST /farmers/{fid}/products/{fspid}NOTE: throughout this API we use PUT for updates, the reason we're using POST in this case is to show partial updates. Modifies product identified by {fspid} in the farmer's store identified by {fid}. HTTP response code: 200 (OK). The body of the response will be empty. If the account identified by {fid} doesn't exist or the product identified by {fspid} don't exist, then the HTTP response code will be 404 (Not Found). 'Location' header with link to /farmers/{fid}/products/{fspid}. Resource URL/farmers/{fid}/products/{fspid} Parametersnote (optional): a personal description of the product; will be displayed next to the general catalog product name when the customer looks at farmer's store. start_date (optional): date of the year, e.g. "MM-DD" when the product becomes available; if not specified then the product is available starting with the first day of the year. end_date (optional): date of the year, e.g. "MM-DD" when the product is last available; if not specified, then the product is available through the last day of the year. price (optional): price per unit of product. product_unit (optional): what is the unit for which the price is defined, e.g. "lb", "floz", "Kg", etc. image (optional): URL for the picture of this store product. Example Request
Here is data being POST-ed
Example ResponseThe body of the response is empty. GET /farmers/{fid}/products/{fspid}Get the detail for product identified by {fspid} in the farmer's store identified by {fid}. HTTP response code: 200 (OK). If the account identified by {fid} doesn't exist or the product identified by {fspid} don't exist, then the HTTP response code will be 404 (Not Found). Resource URL/farmers/{fid}/products/{fspid} ParametersNone. Example Request
Example Response
Reports
GET /farmers/{fid}/reportsReturns an array of available report IDs with their corresponding names. The same reports are available to all farmers. HTTP response code: 200 (OK). Resource URL/farmers/{fid}/reports ParametersNone. Example Request
Example Response
GET /farmers/{fid}/reports/{frid}[?start_date=YYYYMMDD&end_date=YYYYMMDD]Returns the report identified by {frid} populated with data that is specific to the farm identified by {fid}. If a start_date and end_date are provided, then use those to narrow the result set for the report. HTTP response code: 200 (OK) or 404 (Not Found) if {fid} or {frid} are invalid. Resource URL/farmers/{fid}/reports/{frid} 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 Request
Example Response
Another Example Request
Example Response
GET /farmers/{fid}/delivery_chargeReturns the current value of the delivery fee for the farm identified by {fid}. HTTP response code: 200 (OK). Resource URL/farmers/{fid}/delivery_charge ParametersNone. Example Request
Example Response
POST /farmers/{fid}/delivery_chargeModifies the delivery charge. 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/{fid}/delivery_charge. The body of the response will be empty. Resource URL/farmers/{fid}/delivery_charge Parametersdelivery_charge (required): the new delivery charge (aka delivery fee) amount. Example Request
Here is data being POST-ed
Customers
POST /customersCreates an account and returns (in the body of the response) the ID of the account. 'Location' header with link to /customers/{cid} where {cid} is the newly assigned ID for the farmer account. HTTP response code: 201 (Created). Resource URL/customers Parameters
Example Request
Here is data being POST-ed
Example Response
PUT /customers/{cid}Replaces the account information for the account identified by {cid} with the information in the body of the PUT request. HTTP response code: 200 (OK). The body of the response will be empty. If the account identified by {cid} doesn't exist, then the HTTP response code will be 404 (Not Found). Resource URL/customers/{cid} Parameters
Example Request
Here is data being PUT
Example ResponseThe body of the response is empty. GET /customers/{cid}Returns detailed information about the customer identified by {cid}. HTTP response code: 200 (OK) or 404 (Not found) if the account identified by {cid} doesn't exist. Resource URL/customers/{cid} ParametersNone. Example Request
Example Response
POST /customers/{cid}/ordersCreates an order for the customer identified by {cid} and returns (in the body of the response) the ID of the order. 'Location' header with link to /customers/{cid}/orders/{oid} where {oid} is the newly assigned ID for the order. HTTP response code: 201 (Created). If {cid} doesn't exist then the response code is 404. Resource URL/customers/{cid}/orders Parameters
NOTE: the units for "amount" will be those listed for the product in the farmer's catalog. For example, if the product is potatoes and the "product_unit" for potatoes is "lb", then an order where the "amount" is 1.5 is understood to be 1.5 lb. Example Request
Here is data being POST-ed
Example Response
GET /customers/{cid}/ordersReturns an array of all orders placed by the customer identified by {cid}. HTTP response code: 200 (OK) if {cid} is valid, 404 (Not Found) otherwise. Resource URL/customers/{cid}/orders ParametersNone Example Request
Example Response
GET /customers/{cid}/orders/{oid}Returns order detailed for the order identified by {oid) placed by the customer identified by {cid}. HTTP response code: 200 (OK) if {cid} and {oid} are valid, 404 (Not Found) otherwise. Resource URL/customers/{cid}/orders/{oid} ParametersNone Example Request
Example Response
POST /customers/{cid}/orders/{oid}Cancels the order identified by {oid} placed by customer {cid}. HTTP response codes: 204 (No Content), 400 (Bad Request) if data is missing from the request or is malformed. 'Location' header with link to /customers/{cid}/orders/{oid}. The body of the response will be empty. Resource URL/customers/{cid}/orders/{oid} Parametersstatus (required): the only acceptable value is "cancelled". Example Request
Here is data being POST-ed
Managers
GET /managers/catalogReturns an array of all products in the general catalog. HTTP response code: 200 (OK). Resource URL/managers/catalog ParametersNone Example Request
Example Response
POST /managers/catalogTakes a product and adds it to the catalog. The body of the response will contain the ID of the new product. HTTP response code: 201 (Created). Resource URL/managers/catalog Parametersname (required): the name of the product Example Request
Here is data being POST-ed
Example Response
POST /managers/catalog/{gcpid}Updates the catalog product identified by {gcpid}. HTTP response code: 200 (OK) if the product identified by {gcpid} exists, otherwise 404 (Not found). Resource URL/managers/catalog/{gcpid} Parametersname (required): the name of the product Example Request
Here is data being POST-ed
Example ResponseThe body of the response is empty. GET /managers/accountsReturns an array of all manager accounts. The system always starts with a manager account; this manager can then create another account, etc. HTTP response code: 200 (OK). Resource URL/managers/accounts ParametersNone Example Request
Example Response
GET /managers/accounts/{mid}Returns the account information for the manager identified by {mid}. HTTP response code: 200 (OK) if {mid} exists, otherwise 404 (Not Found) Resource URL/managers/accounts/{mid} ParametersNone Example Request
Example Response
ReportsGET /managers/reportsReturns an array of available report IDs with their corresponding names. HTTP response code: 200 (OK). Resource URL/managers/reports ParametersNone. Example Request
Example Response
GET /managers/reports/{mrid}[?start_date=YYYYMMDD&end_date=YYYYMMDD]Returns the report identified by {mrid}. If a start_date and end_date are provided, then use those to narrow the result set for the report. HTTP response code: 200 (OK) or 404 (Not Found) if {mrid} is invalid. Resource URL/managers/reports/{mrid} 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 Request
Example Response
Another Example Request
Example Response
SearchGET /search?topic=topicword&key=keywordReturns all entities within the "topic" ("topicword" can be one of "farm", "customer", "order") that match the "key" ("keyword" is a single word string, e.g. "bob", "123-4", etc.) HTTP response code: 200 (OK), or 404 if "topicword" has a value that's not allowed. Resource URL/search?topic=topicword&key=keyword Parameterstopic (required): the topic for search. The value for topic can be any of "farm", "customer", "order". key (required): the search key. Anything that matches the keyword (the value of key) will be included in the result set. The search is case insensitive. If keyword is empty, then match everything. Example Request
Example Response
Here is another example, this time for the "customer" topic. Example Request
Example Response
Here is an example with the "order" topic. Example Request
Example Response
DeliveryPOST /delivery/{oid}Updates the order identified by {oid}. HTTP response code: 200 (OK) if the order identified by {oid} exists, otherwise 404 (Not found). Resource URL/delivery/{oid} ParametersNone. Example Request
Here is data being POST-ed
Example ResponseThe body of the response is empty.
$Id: project-api.html,v 1.14 2016/11/09 23:15:20 virgil Exp $ |