This endpoint within the Unified Rail API allows for UK Railway staions to be searched.

The intention is for this to be used by some remote component like jQuery so the end user can start typing part of a station's name and they get a real time display of results as they type.

API Rate limitations

Because of it's intended use to respond to a user in real time as they type in some HTML5 search component, this API has no rate limitations.

You are free to call this end point as many times as required. However you must not employ any anti-cache techniques in the calls.

The underlying data doesn't change often so emplying an anti-cache technique will only slow down your end-user experience and increase load on our servers.

You are still bound to all other terms within the API's Conditions of Use.


Performing a search

To use simply make an HTTP GET request to http://api.area51.onl/rail/1/search with your search term in the q query parameter. The API will then respond with a JSON array containing 0 or more objects, one per result. Each result object contains three properties:

code
The stations 3Alpha or CRS code
name
The station's name
label
A combination of name and code that can be used for display

For example, say we want to search for Maidstone, and the end user as typed maid then an example API call would be:

$ curl -s 'http://api.area51.onl/rail/1/search/maid'
[{"code":"MDN","name":"Maiden Newton","label":"Maiden Newton [MDN]"},{"code":"MAI","name":"Maidenhead","label":"Maidenhead [MAI]"},{"code":"MDB","name":"Maidstone Barracks","label":"Maidstone Barracks [MDB]"},{"code":"MDE","name":"Maidstone East","label":"Maidstone East [MDE]"},{"code":"MDW","name":"Maidstone West","label":"Maidstone West [MDW]"}]

Here's the response made easier to read:

$ curl -s 'http://api.area51.onl/rail/1/search/maid' | jq '.'
[
  {
    "code": "MDN",
    "name": "Maiden Newton",
    "label": "Maiden Newton [MDN]"
  },
  {
    "code": "MAI",
    "name": "Maidenhead",
    "label": "Maidenhead [MAI]"
  },
  {
    "code": "MDB",
    "name": "Maidstone Barracks",
    "label": "Maidstone Barracks [MDB]"
  },
  {
    "code": "MDE",
    "name": "Maidstone East",
    "label": "Maidstone East [MDE]"
  },
  {
    "code": "MDW",
    "name": "Maidstone West",
    "label": "Maidstone West [MDW]"
  }
]
        

Datasets

The search API uses the location table in the Darwin reference feed to provide the Station's name, 3Alpha/CRS and TipLoc codes.

3Alpha or CRS code

When the term is exactly 3 characters then it will look for a matching code as well as any station names that contain those characters. If a 3Alpha code is matched then it's placed at the start of the response.

For example: if the user typed mde (3Alpha MDE is Maidstone East) then you would get 2 results, Maidstone East first as its MDE & Camden Road as Camden contains the letters mde.

$ curl -s 'http://api.area51.onl/rail/1/search/mde' | jq '.'
[
  {
    "code": "MDE",
    "name": "Maidstone East",
    "label": "Maidstone East [MDE]"
  },
  {
    "code": "CMD",
    "name": "Camden Road",
    "label": "Camden Road [CMD]"
  }
]

TipLoc's

TipLocs (Timing Point Locations) are another form of identifying stations (as well as other intermediate points) on the Rail Network. They are formed of 4 to 7 characters, so for terms that fit that range then the API will search for them as well.

For example if the user typed victr which is short for London Victoria's tiplocs VICTRIA, VICTRIC & VICTRIE then it returns

$ curl -s 'http://api.area51.onl/rail/1/search/victr'
[{"code":"VIC","name":"London Victoria","label":"London Victoria [VIC]"}]

Postcode

Any search term which consists of 1 or 2 letters followed by a digit will cause a search against UK Postcodes. In this mode the results will be the nearest 10 stations from that postcode or [] if no postcode was found. Note spaces are ignored in the search term if provided.

For example, doing a search against ME14 1QN (Postcode for Maidstone East) gives us the following result:

$ curl -s 'http://api.area51.onl/rail/1/search/ME14 1QN'|jq '.'
[
  {
    "code": "MDE",
    "name": "Maidstone East",
    "label": "Maidstone East [MDE] 0.1km"
  },
  {
    "code": "MDB",
    "name": "Maidstone Barracks",
    "label": "Maidstone Barracks [MDB] 0.4km"
  },
  {
    "code": "MDW",
    "name": "Maidstone West",
    "label": "Maidstone West [MDW] 0.8km"
  },
  {
    "code": "BMG",
    "name": "Barming",
    "label": "Barming [BMG] 3.0km"
  },
  {
    "code": "EFL",
    "name": "East Farleigh",
    "label": "East Farleigh [EFL] 3.5km"
  },
  {
    "code": "BSD",
    "name": "Bearsted",
    "label": "Bearsted [BSD] 4.0km"
  },
  {
    "code": "AYL",
    "name": "Aylesford",
    "label": "Aylesford [AYL] 4.6km"
  },
  {
    "code": "EML",
    "name": "East Malling",
    "label": "East Malling [EML] 5.7km"
  },
  {
    "code": "NHE",
    "name": "New Hythe",
    "label": "New Hythe [NHE] 6.0km"
  },
  {
    "code": "WMA",
    "name": "West Malling",
    "label": "West Malling [WMA] 7.3km"
  }
]