Skip to content

Search Transport by ID

Daniel Cronqvist edited this page Dec 11, 2020 · 1 revision

Search Transport by ID - HTTP POST

Endpoint: https://co2.dcronqvist.se/transports/search/id

Example cURL POST:

$ curl -X POST -d '{ "_id": [100, 2] }' -H "Content-Type: application/json" 127.0.0.1:5000/transports/search/id

Expected payload format (EPF)

The following rules are applied to all keys in the payload using the EPF as a sample:

  1. Keys with arrays of specified types specify which types that are allowed for that specific key.
  2. Keys with specific values only allow that specific value in the payload.
  3. Keys that contain objects are recursively checked using rule 1 and 2.
{
    "_id": ["list:int"],
}

Responses

200 OK

All of the transports that it finds based on the array of ID's you specified in the request, you get a response with an array of all the transports that it finds.

{
    "response": [ { 
        "_id": 100, 
        "type": "transport", 
        "type_description": "train", 
        "impact": {
            "co2_per_kg_km":0.005, 
            "measurement_error": 0.11, 
            "distance_travelled": 14000, 
            "energy_sources":["nuclear", "coal"]
        }, 
        "start_lat": 27.19, 
        "start_lon": 113.69, 
        "end_lat": 27.49, 
        "end_lon": 119.66, 
        "max_weight": 3219
    } ],
    "status_code": 200,
    "status": "200 OK"
}

400 Bad Request

If you receive a 400 BAD REQUEST, you either have missed a key or have specified a disallowed type for a specific key.

{
    "response": "ERROR: Missing key '_id'",
    "status_code": 400,
    "status": "400 BAD REQUEST"
}

405 Method Not Allowed

If you receive a 405 METHOD NOT ALLOWED, you are trying to access this POST endpoint by using some other HTTP method than POST.

{
    "response": null, 
    "status": "405 METHOD NOT ALLOWED", 
    "status_code": 405
}