Skip to content

HTTP API

justjkk edited this page Dec 10, 2014 · 2 revisions

Publish Transaction

URL Pattern: http://analytics.example.net/resource/<Resource>/
Request Method: POST
Request Data: tr_type=(insert|delete)&payload=<TransactionJSON>

Response Code: (202|400|503)
Response: JSON response with keys "status". If 400 or 503, "error_message" and "error_context" are provided.

A response code of 202 is sent when the transaction is successfully published.
Note: This doesn't mean the analytics worker successfully processed the request. Currently, there is no way for the client to know if the worker succeeded processing. This may be possible in the future.

A response code of 400 is sent in case of bad POST data. The payload is not checked though.

A response code of 503 is sent when the publish definitely fails because all/some analytics worker processes are down.

The examples depicts usage in an Online Bus ticket booking system(think Redbus).

Example-1:

URL: http://analytics.example.net/resource/Ticket/
POST Data:
    tr_type=insert
    payload={"From": "Chennai", "To": "Bangalore", "TravelsID": "1325", "Fare": 300.00, "Departure": "2012-01-22 10:45:00", "Arrival": "2012-01-23 06:00:00"}

Response Code: 202

Response-1:

{
  "status": "Accepted"
}

Example-2:

URL: http://analytics.example.net/resource/Ticket/
POST Data:
    tr_type=update
    payload={"From": "Chennai", "To": "Bangalore", "TravelsID": "1325", "Fare": 300.00, "Departure": "2012-01-22 10:45:00", "Arrival": "2012-01-23 06:00:00"}

Response Code: 400

Response-2:

{
  "status": "BadRequest",
  "error_message": "Unknown transaction type",
  "error_context": "update"
}

Retrieving Analytics

URL Pattern: http://analytics.example.net/analytics/<AnalyticsID>/
Request Method: GET
Request Data: <query_dimension1>=<value1_range>&<query_dimension2>=<value2_range>&...

Response Code: (200|400|503)
Response: JSON response with keys "status". If 400 or 503, "error_message", "error_context" are provided. If 200, "data" contains the analytics output.

Example-1:

URL: http://analytics.example.net/analytics/travels_monthly_revenue/?Month=Dec-2011&TravelsID=1325

Response Code: (200|400|503)

Response-1:

{
  "status": "OK",
  "data" : "<Refer Output Format wikipage>"
}

Example-2:

URL: http://analytics.example.net/analytics/travels_monthly_revenue/?Month=20110101..20111201

Response Code: (200|400|503)

Response-2:

{
  "status": "Bad Request",
  "error_message": "Missing slice parameter",
  "error_context": "TravelsID"
}

Example-3:

URL: http://analytics.example.net/analytics/travels_daily_revenue/?Month=20120115..20120230&TravelsID=1325

Response Code: (200|400|503)

Response-3:

{
  "status": "Bad Request",
  "error_message": "Invalid date",
  "error_context": "20110230"
}
Clone this wiki locally