node src/dummy.js
initializes the data to test the program
npm start
starts the json server to fake the api
node src/main.js
executes the algorithm and saves the data into retrieved_products.json
file
Hello developer,
Thank you very much for your interest in Apify and the Web Automation Developer position. Before we meet personally over a call, we would like to see if you are ready for the position. Most of what developers do is write code and solve problems so we present to you a real-world exercise that will contain both of these aspects.
- The goal of the exercise is to find out if you can write solid code and solve problems.
- Try to finish the exercise as soon as possible. There isn’t a hard deadline but we might prefer earlier candidates. From our experience, candidates take between 2 hours and 2 days to deliver the solution.
- Please do not fake it by asking your more experienced friend. We will find out and it will erode the trust between us.
- Take your time and think it through. Write nice and clean code. Add comments explaining complex parts. Solve it but then refactor it to a robust and readable solution.
- We will not explain the exercise in the middle, you have to send us the whole solution at once. But we are happy if you write comments about what was not clear and why you solved it the way you did.
- You can choose your favourite programming language but we prefer JavaScript/TypeScript
- Once you solve the problem, try to optimize it so it uses the least amount of requests.
- Your goal is to extract all products from an imaginary e-commerce JSON API with limited results per search. The API URL origin is
[https://api.ecommerce.com/products](https://api.ecommerce.com/products)
. This URL doesn’t exist (it is only imaginary) so don’t try to run the code 🙂 - The API is called via a simple GET request without a need for special headers and it will return JSON data.
- Every API call will return max 1000 products. Your goal is to overcome this limitation by creating requests for specific price ranges of products. You don’t know upfront how many products there are total but this number is returned from the API.
- Each product on the API costs somewhere between $0 and $100,000.
- You can make the request more specific by adding a
minPrice
andmaxPrice
query parameters. This way we can overcome the 1000 limit of results per API call. - Create an algorithm that will ensure that all products are scraped and accumulate all products into a single array called
products
. - This is an example response of the JSON API.
total
means how many products there are on the API for this price range (it will be a different number for whole website or different price range).count
means how many were returned on this API call (max is 1000).products
is an array with the length ofcount
. We don't care about what is inside the product objects.
{
"total": 99999,
"count": 1000,
"products": [{}, {}, ...]
}
- Is there some expectations your code relies on? If yes, write it in the comments. Could the code be written in a way that does not depend on these expectations?