# Target Interview - USA
myRetail is a rapidly growing company with HQ in Richmond, VA and over 200 stores across the east coast. myRetail wants to make its internal data available to any number of client devices, from myRetail.com to native mobile apps.
The goal for this exercise is to create an end-to-end Proof-of-Concept for a products API, which will aggregate product data from multiple sources and return it as JSON to the caller. Your goal is to create a RESTful service that can retrieve product and price details by ID. The URL structure is up to you to define, but try to follow some sort of logical convention. Build an application that performs the following actions: Responds to an HTTP GET request at /products/{id} and delivers product data as JSON (where {id} will be a number.
Example product IDs: 15117729, 16483589, 16696652, 16752456, 15643793) Example response: {"id":13860428,"name":"The Big Lebowski (Blu-ray) (Widescreen)","current_price":{"value": 13.49,"currency_code":"USD"}}
Performs an HTTP GET to retrieve the product name from an external API. (For this exercise the data will come from redsky.target.com, but let’s just pretend this is an internal resource hosted by myRetail)
Reads pricing information from a NoSQL data store and combines it with the product id and name from the HTTP request into a single response.
BONUS: Accepts an HTTP PUT request at the same path (/products/{id}), containing a JSON request body similar to the GET response, and updates the product’s price in the data store.
- Retrieve product and price information by Product Id.
- Update the price information in the database.
- Secure API with basic authentication.
- One rest end point is not recure.
- Implement Swagger2 for API documentation
Method Request Credentials
GET /products/{id} [SECURE -- normaluser/normaluser]
PUT /products/{id} [SECURE -- admin/admin]
GET /products [NOT SECURE]
-
Spring Boot : https://start.spring.io/ https://spring.io/guides/gs/serving-web-content/
-
Feign: Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations. https://cloud.spring.io/spring-cloud-netflix/
-
Maven: https://maven.apache.org/
-
Mokito/Junit: http://site.mockito.org/
-
Postman: https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en
- Java 1.7
- Eclipse Mars: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/mars2
- Install Mongo DB: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
- Install Maven: https://www.mkyong.com/maven/how-to-install-maven-in-windows/
- Github: Download project from the following git repository https://github.com/rohitdec01/myRetail
a) Download as a ZIP file OR
b) Clone the git project from git-bash or command prompt (You must have git setup)
- Import the project into eclipse – File->import
Test cases are present on the following directory. I have written some test cases for controller class and service class using mokito. I am using mokito for mockdata.
C:\WORK_ENV\workspace\myRetail\src\test\java
To run the test Go to project folder and trigger following command on the command prompt ( or gitbash).
mvn test.
Run mongo DB from the command prompt. And test --- http://localhost:27017/ (default port) Go to the project folder and trigger the command:
mvn spring-boot:run
The end point of this application is fully secure. There are 3 users in this application.
- admin/admin --- Can update price information and get the product by prodctId.
- normaluser/normaluser -- get the product by prodctId.
- dbuser/dbuser -- get the product by prodctId.
http://localhost:8080/swagger-ui.html
GET: With valid product but no credentials (http://localhost:8080/products/13860428)
GET: with valid product and admin credentials (http://localhost:8080/products/13860428)
GET: Wrong product ID and valid credentials admin/admin (http://localhost:8080/products/13860428)
PUT Request: With Valid product Idand admin/admin credentials (http://localhost:8080/products/13860428)
PUT Request: With Valid product Id and normaluser/normaluser credentials (http://localhost:8080/products/13860428)