For your assignment, we need to ensure you can be successful on our team working in the backend api.
This challenge is to build an API for the http server to receive POST requests with information about a visitor and respond with a decision, either: rejection, or accept with a corresponding target url.
Specifically you need to:
- Set up Git for this repo locally
- Solve the challenge locally
- Create a new repo in your GitHub account and note the git url
- Set your local origin to the new git url: git remote set-url origin ${git url}
- Push your solution to the newly set origin
You must follow these steps for your solution to be accepted -- forks or other methods will not be considered.
- The decisions should be based on information about the visitor that comes in POST request body
{
"geoState": "ca",
"publisher": "abc",
"timestamp": "2018-07-19T23:28:59.513Z"
}
- No
target
can receive more traffic per day than it allows. Here's an exampletarget
with max 10 accepts per day
{
"id": "1",
"url": "http://example.com",
"value": "0.50",
"maxAcceptsPerDay": "10",
"accept": {
"geoState": {
"$in": ["ca", "ny"]
},
"hour": {
"$in": [ "13", "14", "15" ]
}
}
}
-
All remaining
targets
should be filtered by criteria they are willing to accept. The abovetarget
example only accepts visitors from either California or New York from 13 to 16 UTC. -
If no
targets
are left, the request is rejected (returns{"decision":"reject"}
), otherwise it should return the url of the remainingtarget
with the highest value.
-
New endpoints that needs to be built:
- POST
/api/targets
- post a target
- GET
/api/targets
- get all targets
- GET
/api/target/:id
- get a target by id
- POST
/api/target/:id
- update a target by id
- POST
/route
- post a request with information about the visitor
- respond with a decision
- POST
-
API functional tests.
- each endpoint should have its own test
- write all tests in
test/endpoints.js
- be sure to understand how
servertest
works
- All persistence should use redis.
- Source code should be in
lib
dir. - Use redis client factory from
lib/redis.js
and do not edit this file.