ADSP-EcoTrekker-Project / EcoTrekker

3 stars 1 forks source link

Endpoint API Definition Co2 Calculator Service #43

Closed Andy3189 closed 8 months ago

Andy3189 commented 9 months ago

Co2 Calculator Rest Endpoint Documentation

/v1/calc/co2

This endpoint calculates the CO2 emissions for a route.

HTTP Method

POST

Request

The request must be in JSON format and contain a route consisting of steps with a vehicle, a start and endpoint and/or a distance in meters.

Headers

Content-Type: application/json

Body

{
    "steps": [
        {
            "start": "Alexanderplatz",
            "end": "Gesundbrunnnen",
            "vehicle": "U8",
            "distance": 1500
        },
        {
            "start": "Gesundbrunnnen",
            "end": "Westhafen",
            "vehicle": "S41",
            "distance": 400
        }
    ]
}

Response

Success

The response is a JSON object containing the co2 (in g) parameter for this route. The successfull response code is 200.

{
    "co2": 200,
}

Error

In case there is invalid route data, the return code is 400 and a JSON containing the reason

{
    "error": "Invalid route"
}