Giter VIP home page Giter VIP logo

challenge-buyer-router's Introduction

Code Challenge

This challenge is to route traffic according to buyer rules. You will set up an http server that can create and retrieve "buyers". The http server will also route traffic according to the preferences of the buyers.

Create a module lib/server.js that exports a function. This function, createServer, when invoked, should return an http server with the following endpoints:

  • POST /buyers
  • GET /buyers/:id
  • GET /route

All persistence should use redis. See test/index.js for more details.

POST /buyers

This endpoint accepts a JSON body representing a "buyer" like the following example:

{
  "id": "c",
  "offers": [
    {
      "criteria": {
        "device": ["desktop"],
        "hour": [0, 1, 2],
        "day": [0],
        "state": ["CA"]
      },
      "value": 50,
      "location": "http://0.c.com"
    }
  ]
}

The buyer has two top-level properties, id and offers. offers is an array of what the "buyer" is offering to buy. In the example, if a request object has the device "desktop", an hour that is one of "0", "1", or "2", a day of "0", and state "CA", that buyer will pay a value of 50 for it to go to location "http://0.c.com".

GET /buyers/:id

This retrieves a "buyer" document by :id. Example /buyers/c for the above "buyer".

GET /route

This will compare a request object to the offers of the "buyers" and route traffic to the highest valued matching location. Parameters for this endpoint:

  • timestamp: ISO timestamp (e.g. new Date().toISOString())
  • device: "desktop" or "mobile"
  • state: US State (e.g. "CA", "NY")

Example Request:

GET /route?timestamp=2017-03-12T10%3A30%3A00.000Z&state=NV&device=mobile

Example Response Headers:

{ location: http://0.c.com }

challenge-buyer-router's People

Contributors

davidguttman avatar

Watchers

Santosh Suresh avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.