Skip to content

Instantly share code, notes, and snippets.

@matthewmorek
Created March 7, 2023 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmorek/119cae457aca80c8309bff07903fb018 to your computer and use it in GitHub Desktop.
Save matthewmorek/119cae457aca80c8309bff07903fb018 to your computer and use it in GitHub Desktop.
API Documentation

Tramspotter API

Tramspotter API provides endpoints for serving Metrolink tram data to Tramspotter apps. It kinda acts as a Metrolink API proxy, as it provides data in a more readable JSON format.

Dependencies

This project is build with Deno. Make sure Deno is installed on your machine, if not you can always refer to installation manual.

Getting started

Pull this repo to your local machine, and from its working directory you can run the dev server.

deno task dev

Here's a list of the routes available in Tramspotter API. Open endpoints require no authentication. All endpoints are rate-limited to 60 req/min.

Stations

GET /stations

Description

Get a list of all available tram stops that operated by Manchester Metrolink network (TfGM) in a GeoJSON format.

Return format

Successful response will bear a HTTP Status Code of 200 OK. Here's an example of what a valid response may look like.

Request

/stations

Response

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [-2.26380062418, 53.38009116916]
      },
      "properties": {
        "atcoCode": "9400ZZMAWYT2",
        "naptanCode": "mantwjdt",
        "name": "Wythenshawe Town Centre (Manchester Metrolink)",
        "description": "Wythenshawe Town Centre Ainley Road"
      }
    }
  ]
}

Errors

The following HTTP errors may be encountered when using this endpoint:

  • 405 Method Not Allowed
  • 408 Request Time Out
  • 500 Internal Server Error
  • 503 Service Not Available
{
  "success": false,
  "errors": [
    {
      "status": 500,
      "title": "Problem with parsing source XML dataset"
    }
  ]
}

Timetables

GET timetables/:id

Description

Get an up-to-date timetable in JSON format for a given AtcoCode supplied as :id.

Return format

Successful response will bear a HTTP Status Code of 200 OK. Here's an example of what a valid response may look like.

Request

/timetables/9400ZZMATIM1

Response

{
  "arrivals": [
    {
      "carriages": "Double",
      "destination": "Altrincham",
      "status": "Due",
      "wait": 1,
      "id": "76297a62-2762-421f-ac22-c004ff707be3"
    },
    {
      "carriages": "Single",
      "destination": "Piccadilly",
      "status": "Due",
      "wait": 4,
      "id": "bf66bd7d-7749-413e-b094-e755b39087a9"
    }
  ],
  "lastUpdated": "2023-03-07T17:19:01Z",
  "line": "Altrincham",
  "messageBoard": "On Thursday 9th March Manchester United welcome Real Betis to Old Trafford. Please allow extra time for travel",
  "timestamp": 1678209547186
}

Errors

The following HTTP errors may be encountered when using this endpoint:

  • 400 Bad Request
  • 404 Not Found
  • 405 Method Not Allowed
  • 408 Request Time Out
  • 500 Internal Server Error
  • 503 Service Not Available
{
  "success": false,
  "errors": [
    {
      "status": 500,
      "title": "Problem with parsing source XML dataset"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment