Skip to content

REST‐API

JG edited this page Sep 29, 2023 · 8 revisions

Introduction

The syntax for the request body and response body will be a mixture of Typescript and JSON. That means a valid example for

{
    hello?: string
}

would be

{
    hello: "hello"
}

and also

{
}

Login

POST /api/login

Requestbody:

{
    username: string  // The username that was entered into the login-form
    password: string  // The password that was entered into the login-form
}

Response body:

{
    token: string   // A jwt session token
}

if login with the user data was successful

On error: 401

Init

These routes are only used by the app.

GET /api/init/app/track/:trackId

Description: Get information about the current track such as the tracks id, the tracks name, the GeoJSON path, the length and the POI's.

Response body:

{
	trackId: number
	trackName: string                          // The name of the track, e.g. 'Malente-Lütjenburg'
	trackPath: FeatureCollection<LineString>   // The path of the track as a linestring
	trackLength: number                        // The length of the track in km 
	pointsOfInterest: PointOfInterest[]        // A list of points of interest on the given track
}

with PointOfInterest

{
	id: number
	percentagePosition: number // A position mapped onto percentage 0-100 e.g. 0% Malente; 100% Lütjenburg
	typeId: number             // Maps as Generic = 0,	LevelCrossing = 1, LesserLevelCrossing = 2, Picnic = 3, TrackEnd = 4, TurningPoint = 5
	name: string               // Name of the POI such as 'Haltepunkt Friederikental'
	description?: string       // Optional description of the poi
	pos: Position              // A GPS position of the poi
	isTurningPoint: boolean    // Can a vehicle be turned at this poi?
	trackId: number            // Id of the track the poi is on
}

and Position

{
	lat: number  // Latitude of the GPS position
	lng: number  // Longitude of the GPS position
}

GET /api/init/app/tracks

Description: Get some basic information (id, start, end) about all tracks within the system.

Response body:

[
    {
	id: number
	name: string // E.g. "Malente-Lütjenburg"
    },...
]

PUT /api/init/app

Description: Get track information for track that is closest to the current position.

Request body:

{
	pos: Position
}

Response body:

{
	trackId: number
	trackName: string                          // The name of the track, e.g. 'Malente-Lütjenburg'
	trackPath: FeatureCollection<LineString>   // The path of the track as a linestring
	trackLength: number                        // The length of the track in km 
	pointsOfInterest: PointOfInterest[]        // A list of points of interest on the given track
}

Vehicles

PUT /api/vehicles/app/getId

Description: Get database uid of a vehicle for the app. Vehicles-names are unique for a track.

Request body:

{
    vehicleName: string
    trackId: number
}

Response body:

{
    vehicleId: number
}

PUT /api/vehicles/app

Description: Optionally get position of app and return information about close vehicles for the particular vehicle.

Request body:

{
    vehicleId: number
    pos?: Position      // the current position of user
    speed?: number      // Speed in km/h
    heading?: number    // Heading of the vehicle between 0 and 359
    timestamp?: number  // Timestamp of gps measurement in milliseconds since epoch
}

Responsebody:

{
    pos: Position                      // The current position as measured by vehicle
    heading: number                    // Heading of the vehicle between 0 and 359
    vehiclesNearUser: VehicleApp[]     // Vehicles that should be marked on the map
    percentagePositionOnTrack: number  // Percentage (0-100) e.g. 0% Malente; 100% Lütjenburg
    speed: number                      // Speed in km/h
    passingPosition?: Position         // Only set if needed
}

with VehicleAppas

{
    id: number
    name: string                 // The track-unique vehicle name
    track: number                // The tracks id
    type: number                 // The VehicleType id
    trackerIds: string[]         // Some associated trackers
    pos?: Position               // undefined if position is unknown.
    percentagePosition: number   // A position mapped onto percentage 0-100) e.g. 0% Malente; 100% Lütjenburg
    heading: number              // between 0 and 360
    headingTowardsUser?: boolean // Is the other vehicle heading towards the user?
}

GET /api/vehicles

Description: Get information of all vehicles.

Response body:

[
{
    id: number
    name: string           // Vehicles name that is track-unique
    type: number           // VehicleType Id
    trackerIds: string[]
    track: number          // Track Id
},...
]

GET /api/vehicles/:vehicleId

Description: Get information for vehicle with specific id.

Response body:

{
    id: number
    name: string              // Vehicles name that is track-unique
    type: number              // VehicleType Id
    trackerIds: string[]
    track: number             // Track id
}

POST /api/vehicles

Description:

Create a new vehicle.

Request body:

{
    name: string         // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
    track: number        // Track id for vehicle
    type: number         // The id of the type
    trackerIds: string[] // A possibly empty list of unique ids to identify the trackers belonging to that vehicle
}

Response body:

Contains only the unique id of the newly created vehicle.

PUT /api/vehicles/:vehicleId

Description: Update vehicle by id.

Request body:

{
    name: string           // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
    track: number          // Track id for vehicle
    type: number           // The id of the type
    trackerIds: string[]   // A possibly empty list of unique ids to identify the trackers belonging to that vehicle
}

DELETE /api/vehicles/:vehicleId

Description:

Delete a vehicle with a certain uid.

VehicleType

GET /api/vehicletype

Description:

Get a list of all vehicle types that are currently registered.

Response body:

[
    {
        id: number            // A unique id of a vehicle type
        name: string          // A descriptive name of the vehicle type, e.g. "Draisine", "High-Speed Train",..
        description?: string  // Perhaps a description of the type of vehicle, that is falls into this category
        icon: string          // Currently unused but might be added if other rail vehicles that need different icons are used
    }
,...
]

GET /api/vehicletype/:typeId

Description:

Get a specific type by its id.

Response body:

{
    id: number            // A unique id of a vehicle type
    name: string          // A descriptive name of the vehicle type, e.g. "Draisine", "High-Speed Train",..
    description?: string  // Perhaps a description of the type of vehicle, that is falls into this category
    icon: string          // Currently unused but might be added if other rail vehicles that need different icons are used
}

POST /api/vehicletype

Description:

Create a new vehicle type.

Request body:

{
    name: string          // A descriptive name of the vehicle type, e.g. "Draisine", "High-Speed Train",..
    description?: string  // Perhaps a description of the type of vehicle, that is falls into this category
    icon: string          // Currently unused but might be added if other rail vehicles that need different icons are used
}

Response body:

{
    id: number            // A unique id of a vehicle type
    name: string          // A descriptive name of the vehicle type, e.g. "Draisine", "High-Speed Train",..
    description?: string  // Perhaps a description of the type of vehicle, that is falls into this category
    icon: string          // Currently unused but might be added if other rail vehicles that need different icons are used
}

PUT /api/vehicletype/:typeId

Description:

Update a vehicle type.

Request body:

{
    id: number            // A unique id of a vehicle type
    name: string          // A descriptive name of the vehicle type, e.g. "Draisine", "High-Speed Train",..
    description?: string  // Perhaps a description of the type of vehicle, that is falls into this category
    icon: string          // Currently unused but might be added if other rail vehicles that need different icons are used
}

DELETE /api/vehicletype/:typeId

Description:

Delete a vehicle type with a certain uid. It is a soft delete under the hood.

Points of interest

GET /api/poi

Description: Get all POIs.

Response body:

[
    {
        id: number
        typeId: number               // The id of the corresponding poi type
        name: string                 // A name for the poi, such as "Feldweg 2"
        description?: string         // An optional description that can be added to a poi
        pos: Position                // The position of the POI
        isTurningPoint: boolean      // Deprecated currently
        trackId: number              // id of track the poi is on
    },...
]

GET /api/poi/:poiId

Description: Get one POI by its id.

Response body:

{
    id: number
    typeId: number               // The id of the corresponding poi type
    name: string                 // A name for the poi, such as "Feldweg 2"
    description?: string         // An optional description that can be added to a poi
    pos: Position                // The position of the POI
    isTurningPoint: boolean      // Deprecated currently
    trackId: number              // id of track the poi is on
}

POST /api/poi

Description: Create new POI for a specific track.

Request body:

{
    typeId: number               // The id of the corresponding poi type
    name: string                 // A name for the poi, such as "Feldweg 2"
    description?: string         // An optional description that can be added to a poi
    pos: Position                // The position of the POI
    isTurningPoint: boolean      // Deprecated currently
    trackId: number              // id of track the poi is on
}

Response:

{
    id: number    // The unique id of the newly created poi.
}

and HTTP-Status 201.

PUT /api/poi/:poiId

Description: Update a point of interest.

Request body:

{
    id: number
    typeId: number               // The id of the corresponding poi type
    name: string                 // A name for the poi, such as "Feldweg 2"
    description?: string         // An optional description that can be added to a poi
    pos: Position                // The position of the POI
    isTurningPoint: boolean      // Deprecated currently
    trackId: number              // id of track the poi is on
}

Response:

{
    id: number    // The unique id of the updated poi
}

DELETE /api/poi/:poiId

Description: Delete a specific point of interest.

POIType

GET /api/poitype

Description: Get a list of all poitypes.

Response body:

[
    {
        id: number
        name: string          // Name of the poi type such as "Haltepunkt"
        icon: POITypeIcon     // Enum corresponding to certain icons
        description?: string  // An optional additional description
    }
    ,...
]

with POITypeIcon

{
    Generic = 0
    LevelCrossing = 1
    LesserLevelCrossing = 2
    Picnic = 3
    TrackEnd = 4
    TurningPoint = 5
}

GET /api/poitype/:typeId

Description: Get a poitype by id.

Response body:

{
    id: number
    name: string         // Name of the poi type such as "Haltepunkt"
    icon: POITypeIcon    // Enum corresponding to certain icons
    description?: string // An optional additional description
}

POST /api/poitype

Description: Create new poitype.

Request body:

{
    name: string         // Name of the poi type such as "Haltepunkt"
    icon: POITypeIcon    // Enum corresponding to certain icons
    description?: string // An optional additional description
}

Response body:

{
    id: number
    name: string          // Name of the poi type such as "Haltepunkt"
    icon: POITypeIcon     // Enum corresponding to certain icons
    description?: string  // An optional additional description
}

PUT /api/poitype/:typeId

Description: Update poitype.

Request body:

{
    id: number
    name: string          // Name of the poi type such as "Haltepunkt"
    icon: POITypeIcon     // Enum corresponding to certain icons
    description?: string  // An optional additional description
}

DELETE /api/poitype/:typeId

Description: Delete poitype.

Track

POST /api/track

Description: Upload the data with a geojson.

Request body:

{
    start: string                                      //e.g. Malente
    end: string                                        // e.g. Lütjenburg
    path: FeatureCollection<Point, GeoJsonProperties>  // The track as a geojson
}

GET /api/track

Description: Get a list of tracks without the geojson.

Response body:

[
{
    id: number 
    start: string  //e.g. Malente
    end: string    // e.g. Lütjenburg
},...
]

GET /api/track/:trackId

Description: Get specific track information for some track.

Response body:

{
    id: number                 // Positive integer to uniquely identify track
    start: string              // E.g. "Malente"
    end: string                // E.g. "Lütjenburg"
    path: Feature<LineString>  // The geojson path of the track
    length: number             // Total length of the track in meters
}

PUT /api/track/:trackId

Description: Update a track by id.

Request body:

{
    start: string                   //e.g. Malente
    end: string                     // e.g. Lütjenburg
    path: FeatureCollection<Point>  // The track as geojson
}

DELETE /api/track/:trackId

Description: Delete a track by id.

GET /api/track/:trackId/vehicles

Description: Get information about all vehicles on specific track.

Response body:

[
    {
        id: number
	pos?: Position               // undefined if position is unknown.
	percentagePosition?: number  // A position mapped onto percentage 0-100 e.g. 0% Malente; 100% Lütjenburg
	heading?: number             // between 0 and 360
        name: string
   	track: number                // track id
	type: number                 // type id
	trackerIds: string[]
    }
    ,...
]

GET /api/track/:trackId/pois

Description: Get all pois for some track.

Response body:

[
    {
        id: number,
        name: string,
        percentagePosition: number,  // A position mapped onto percentage 0-100 e.g. 0% Malente; 100% Lütjenburg
        typeId: number,
        description?: string,
        pos: Position,               // A gps position of the poi
        isTurningPoint: boolean,     // Can a vehicle be turned at this poi?
        trackId: number
    }
    ,...
]

User management for website

GET /api/user

Description: Get a list of all the available users.

Response body:

[
{
    username: string
},...
]

POST /api/user

Description: Create a new user with a fixed password that later needs to be changed. Only for logged in users.

Request body:

{
    username: string 
    password: string
}

PUT /api/user/password

Description: Change the own password. Only for logged in users. Old password needs to be correct.

Request body:

{
    oldPassword: string 
    newPassword: string
}

PUT /api/user/name

Description: Used to change the own username. Only for logged in users. Old username needs to be correct.

Request body:

{
    oldUsername: string 
    newUsername: string
}

DELETE /api/user/:userId

Description: Used to delete user with userId. Only for logged in users.

Tracker

GET /api/tracker

Description: Get information of all trackers.

Response body:

[
    {
        id: string 
        vehicleId: number | null  // The id of the corresponding vehicle if there is such
        data?: unknown            // optional additional data
    },...
]

GET /api/tracker/:trackerId

Description: Get a specific tracker's information.

Response body:

{
    id: string 
    vehicleId: number | null   // The id of the corresponding vehicle if there is such
    battery?: number           // Voltage of battery  
    data?: unknown             // optional additional data
}

POST /api/tracker

Description: Create a tracker.

Requestbody:

{
    id: string,
    vehicleId: number | null   // The id of the corresponding vehicle if there is such
    battery?: number           // Voltage of battery  
    data?: unknown             // optional additional data
}

Response body:

{
    id: string 
    vehicleId: number | null   // The id of the corresponding vehicle if there is such
    data?: unknown             // optional additional data
}

PUT /api/tracker/:trackerId

Description: Update a specific tracker.

Request body:

{
    id: string 
    vehicleId: number | null   // The id of the corresponding vehicle if there is such
    data?: unknown             // optional additional data
}

DELETE /api/tracker/:trackerId

Description: Delete a specific tracker.

POST /api/tracker/oyster/lorawan

Description: Upload link for the data from the LoRaWAN trackers.

Request body:

{
    end_device_ids: EndDeviceIdsTracker 
    received_at: string 
    uplink_message: UplinkMessageTracker 
}

with EndDeviceIdsTracker:

{
    device_id: string

}

and UplinkMessageTracker:

{
    f_port: number
    decoded_payload: DecodedPayloadTracker
}

and DecodedPayloadTracker:

{
    batV: number
    fixFailed: boolean
    headingDeg: number
    inTrip: boolean
    latitudeDeg: number
    longitudeDeg: number
    speedKmph: number
    type: string
}

POST /api/tracker/oyster/lte

Description: Upload link for the data from the IoT-LTE-trackers.

Request body:

{
    SerNo: number
    IMEI: string
    ICCID: string
    ProdId: number
    FW: string
    Records: LteRecord[]
}

with LteRecord

{
    SeqNo: number
    Reason: number
    DateUTC: string
    Fields: any        // list of heterogenous objects depending on FType
}