Rail Station Information
Rail line and station information, including locations, fares, times, and parking.
JSON - Path Between Stations
Description
Returns a set of ordered stations and distances between two stations on the same line.
Note that this method is not suitable on its own as a pathfinding solution between stations.
Response Elements
Element | Description |
---|---|
Path | Array containing path details (MetroPathItem) |
DistanceToPrev | Distance in feet to the previous station in the list. |
LineCode | Two-letter abbreviation for the line (e.g.: RD, BL, YL, OR, GR, or SV) this station's platform is on. |
SeqNum | Ordered sequence number. |
StationCode | Station code for this station. Use this value in other rail-related APIs to retrieve data about a station. |
StationName | Full name for this station, as shown on the WMATA website. |
Request URL
Request parameters
string
Station code for the origin station. Use the Station List method to return a list of all station codes.
string
Station code for the destination station. Use the Station List method to return a list of all station codes.
Request headers
Request body
Response 200
Default response code.
{
"Path": [
{
"DistanceToPrev": 0,
"LineCode": "SV",
"SeqNum": 1,
"StationCode": "N06",
"StationName": "Wiehle-Reston East"
},
{
"DistanceToPrev": 30867,
"LineCode": "SV",
"SeqNum": 2,
"StationCode": "N04",
"StationName": "Spring Hill"
},
{
"DistanceToPrev": 3634,
"LineCode": "SV",
"SeqNum": 3,
"StationCode": "N03",
"StationName": "Greensboro"
},
{
"DistanceToPrev": 3902,
"LineCode": "SV",
"SeqNum": 4,
"StationCode": "N02",
"StationName": "Tysons Corner"
},
{
"DistanceToPrev": 3440,
"LineCode": "SV",
"SeqNum": 5,
"StationCode": "N01",
"StationName": "McLean"
},
{
"DistanceToPrev": 24745,
"LineCode": "SV",
"SeqNum": 6,
"StationCode": "K05",
"StationName": "E Falls Church"
},
{
"DistanceToPrev": 13156,
"LineCode": "SV",
"SeqNum": 7,
"StationCode": "K04",
"StationName": "Ballston"
},
{
"DistanceToPrev": 2980,
"LineCode": "SV",
"SeqNum": 8,
"StationCode": "K03",
"StationName": "Virginia Square"
},
{
"DistanceToPrev": 2473,
"LineCode": "SV",
"SeqNum": 9,
"StationCode": "K02",
"StationName": "Clarendon"
},
{
"DistanceToPrev": 2687,
"LineCode": "SV",
"SeqNum": 10,
"StationCode": "K01",
"StationName": "Court House"
},
{
"DistanceToPrev": 4936,
"LineCode": "SV",
"SeqNum": 11,
"StationCode": "C05",
"StationName": "Rosslyn"
},
{
"DistanceToPrev": 6993,
"LineCode": "SV",
"SeqNum": 12,
"StationCode": "C04",
"StationName": "Foggy Bottom"
},
{
"DistanceToPrev": 2783,
"LineCode": "SV",
"SeqNum": 13,
"StationCode": "C03",
"StationName": "Farragut West"
},
{
"DistanceToPrev": 2001,
"LineCode": "SV",
"SeqNum": 14,
"StationCode": "C02",
"StationName": "McPherson Square"
},
{
"DistanceToPrev": 2359,
"LineCode": "SV",
"SeqNum": 15,
"StationCode": "C01",
"StationName": "Metro Center"
},
{
"DistanceToPrev": 1561,
"LineCode": "SV",
"SeqNum": 16,
"StationCode": "D01",
"StationName": "Federal Triangle"
},
{
"DistanceToPrev": 2016,
"LineCode": "SV",
"SeqNum": 17,
"StationCode": "D02",
"StationName": "Smithsonian"
},
{
"DistanceToPrev": 2643,
"LineCode": "SV",
"SeqNum": 18,
"StationCode": "D03",
"StationName": "L'Enfant Plaza"
},
{
"DistanceToPrev": 1757,
"LineCode": "SV",
"SeqNum": 19,
"StationCode": "D04",
"StationName": "Federal Center SW"
},
{
"DistanceToPrev": 3052,
"LineCode": "SV",
"SeqNum": 20,
"StationCode": "D05",
"StationName": "Capitol South"
},
{
"DistanceToPrev": 2703,
"LineCode": "SV",
"SeqNum": 21,
"StationCode": "D06",
"StationName": "Eastern Market"
},
{
"DistanceToPrev": 3289,
"LineCode": "SV",
"SeqNum": 22,
"StationCode": "D07",
"StationName": "Potomac Avenue"
},
{
"DistanceToPrev": 3750,
"LineCode": "SV",
"SeqNum": 23,
"StationCode": "D08",
"StationName": "Stadium Armory"
},
{
"DistanceToPrev": 12162,
"LineCode": "SV",
"SeqNum": 24,
"StationCode": "G01",
"StationName": "Benning Road"
},
{
"DistanceToPrev": 7779,
"LineCode": "SV",
"SeqNum": 25,
"StationCode": "G02",
"StationName": "Capitol Heights"
},
{
"DistanceToPrev": 5215,
"LineCode": "SV",
"SeqNum": 26,
"StationCode": "G03",
"StationName": "Addison Road"
},
{
"DistanceToPrev": 7960,
"LineCode": "SV",
"SeqNum": 27,
"StationCode": "G04",
"StationName": "Morgan Blvd"
},
{
"DistanceToPrev": 7256,
"LineCode": "SV",
"SeqNum": 28,
"StationCode": "G05",
"StationName": "Largo Town Center"
}
]
}
Code samples
@ECHO OFF
curl -v -X GET "https://api.wmata.com/Rail.svc/json/jPath?FromStationCode=N06&ToStationCode=G05"
-H "api_key: {subscription key}"
--data-ascii "{body}"
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("api_key", "{subscription key}");
// Request parameters
queryString["FromStationCode"] = "N06";
queryString["ToStationCode"] = "G05";
var uri = "https://api.wmata.com/Rail.svc/json/jPath?" + queryString;
var response = await client.GetAsync(uri);
}
}
}
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample
{
public static void main(String[] args)
{
HttpClient httpclient = HttpClients.createDefault();
try
{
URIBuilder builder = new URIBuilder("https://api.wmata.com/Rail.svc/json/jPath");
builder.setParameter("FromStationCode", "N06");
builder.setParameter("ToStationCode", "G05");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
request.setHeader("api_key", "{subscription key}");
// Request body
StringEntity reqEntity = new StringEntity("{body}");
request.setEntity(reqEntity);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null)
{
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
"api_key": "{subscription key}",
// Request parameters
"FromStationCode": "N06",
"ToStationCode": "G05",
};
$.ajax({
url: "https://api.wmata.com/Rail.svc/json/jPath?" + $.param(params),
type: "GET",
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* path = @"https://api.wmata.com/Rail.svc/json/jPath";
NSArray* array = @[
// Request parameters
@"entities=true",
@"FromStationCode=N06",
@"ToStationCode=G05",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
// Request headers
[_request setValue:@"{subscription key}" forHTTPHeaderField:@"api_key"];
// Request body
[_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if (nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if (nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';
$request = new Http_Request2('https://api.wmata.com/Rail.svc/json/jPath');
$url = $request->getUrl();
$headers = array(
// Request headers
'api_key' => '{subscription key}',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'FromStationCode' => 'N06',
'ToStationCode' => 'G05',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_GET);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
########### Python 2.7 #############
import httplib, urllib, base64
headers = {
# Request headers
'api_key': '{subscription key}',
}
params = urllib.urlencode({
# Request parameters
'FromStationCode': 'N06',
'ToStationCode': 'G05',
})
try:
conn = httplib.HTTPSConnection('api.wmata.com')
conn.request("GET", "/Rail.svc/json/jPath?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Request headers
'api_key': '{subscription key}',
}
params = urllib.parse.urlencode({
# Request parameters
'FromStationCode': 'N06',
'ToStationCode': 'G05',
})
try:
conn = http.client.HTTPSConnection('api.wmata.com')
conn.request("GET", "/Rail.svc/json/jPath?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://api.wmata.com/Rail.svc/json/jPath')
query = URI.encode_www_form({
# Request parameters
'FromStationCode' => 'N06',
'ToStationCode' => 'G05'
})
if uri.query && uri.query.length > 0
uri.query += '&' + query
else
uri.query = query
end
request = Net::HTTP::Get.new(uri.request_uri)
# Request headers
request['api_key'] = '{subscription key}'
# Request body
request.body = "{body}"
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body