Question: Build an API to support a mobile / web app. Secure the mobile app with an API key, and use simple geo-search tools to query
Build an API to support a mobile / web app. Secure the mobile app with an API key, and use simple geo-search tools to query results.
Scenario:
You are working on an app idea for a company that will allow users to report the availability of hard to find items for sale in stores. It will work kind of like istocknow works, but you will allow users to report availability of an item at a store. Customers should be able to view the reported availability at a particular store, or search for a particular item within a certain radius of a given town or zip code.
Requirements:
All endpoints should return their data in JSON.
All endpoints should be secured by an API key and return a 401 unauthorized error if none or an incorrect one is provided.
The app will allow users to report a new item, but you really only need to be concerned with creating/updating/deleting a store object and its nested item list.
The API should have the following endpoints:
GET /store - Gets an array of all stores in the system. (inventory data does not have to be fully populated).
GET /store/
POST /store - Adds a new store to the system. The new store object may contain inventory.
PUT /store/
DELETE /store/
GET /search/items?q=
More examples:GET /search/items?q=airpods&zip=32514&radius=5
Get all items matching the term "airpods" within 5 miles of zip code 32514, listed within 14 days
GET /search/items?q=switch&zip=32514
Get all items matching the term "switch" within a default (20 mile) of zip code 32514, listed within 14 days
GET /search/items?q=apple+watch&city=Atlanta&state=GA&radius=40
Get all items matching the term "apple watch" within 40 miles of the city Atlanta, GA, listed within 14 days
GET /search/items?q=beats+x&age=30
Get all items matching the term "beats x", nationwide, listed within the last 30 days
Note:
This endpoint uses query parameters
q is mandatory and should return a 400 bad request if not provided
Zip, city + state, and radius are optional
If no zip or city + state is given then search for the item nationwide
If a city + state is provided, do a reverse lookup of the zip code and then proceed normally
If a city + state AND a zip code is provided, just use the zip code and ignore the city + state
If no radius is given then assume a 20 mile radius as a default
Age is also optional
If an age is specified, search for stores that have matching items newer than the specified age
If no age is specified, assume that the age is 14 days
Implementation requirements
Tools
Your data needs to be hosted on mLab
You should use the mongoose ORM tool to insert data into the mongoose database
You should use Postman to test your API
Your app should expect data to be POST or PUT as an application/json content type.
Libraries
Use the api key package to secure all endpoints with an api key https://www.npmjs.com/package/apikey
Use the zipcodes package to compute all zip codes in a specific radius and to do town name lookups
https://www.npmjs.com/package/zipcodes
Entity Rules
Store - A store with items for sale.
Track their: name, address, zip code, and items.
A store can have multiple items, which are stored in an array within the store.
Each item should contain a name, description, and quantity
Bonus: (+15 points)
Deploy the app to Heroku. Provide me with the URL of the app, fully functional, on a heroku server.
Bonus: (+25 points)
Construct web app that allows you to search the API you are providing in the first app. You may build this app within your same code base for simplicity's sake, or deploy a separate app to heroku and then consume it from this app. Note that you may have to set up CORS for this to work properly, which isn't that hard to do.
You don't have to worry about creating or editing the inventory for this app, just the searching part.
The app should:
Allow a user to enter a search term and an optional zip code, city, state, mileage radius, and age.
Query the API via http and process the resulting JSON.
Display search results in a list on the screen below the search form (very similar to how project 1 functioned).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
