A powerful and user-friendly C# wrapper for the National Rail Darwin OpenLDBWS API.
Explore the docs »
Darwin.Net is a versatile and efficient C# wrapper for the UK's National Rail Darwin OpenLDBWS API, specifically designed to simplify railway data integration tasks.
Its features include:
- Asynchronous Requests: Leverage the power of async/await to make non-blocking requests.
- HttpClient: By using HttpClient instead of SOAP/WCF, Darwin.Net benefits from improved performance, better resource management, and modern networking capabilities. HttpClient is lighter, faster, and more flexible than its alternatives, making it the ideal choice for a contemporary C# wrapper.
- Multi-platform Support: Harness the cross-platform capabilities of .NET to deploy applications using Darwin.Net on a wide range of operating systems, including Windows, macOS, and Linux.
- Zero Dependencies: Darwin.Net library is self-contained and does not rely on any external packages, making it easy to integrate and maintain in your projects.
To get a local copy built, follow these simple example steps.
- Obtain an API key from National Rail Enquiries
- Clone the repository
git clone https://github.com/rhys-wootton/Darwin.Net.git
- Create an
app.config
file within the Darwin.Net project and add the following<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DarwinApiKey" value="YOUR_API_KEY" /> <add key="DarwinUrl" value="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb12.asmx"/> <add key="DarwinActionNameUrl" value="http://thalesgroup.com/RTTI/2021-11-01/ldb/"/> <add key="DarwinTokenTypeUrl" value="http://thalesgroup.com/RTTI/2013-11-28/Token/types"/> </appSettings> </configuration>
- Build the project
To get started, this single line of code will give you access to all the requests that Darwin.Net can make:
Darwin.Net.Darwin darwin = new Darwin.Net.Darwin();
From here, you are able to call some of the following requests:
int maxArrivals = 10;
Station station = Station.LondonBridge;
TimeSpan timeWindow = TimeSpan.FromMinutes(90);
StationBoard response = await darwin.Requests.GetArrivalBoardAsync(maxArrivals, station, timeWindow);
int maxArrivals = 5;
Station station = Station.GlasgowCentral;
TimeSpan timeWindow = TimeSpan.FromMinutes(60);
TimeSpan offset = TimeSpan.FromMinutes(-60);
StationBoardWithDetails response = await darwin.Requests.GetDepartureBoardWithDetailsAsync(maxArrivals, station, timeWindow, timeOffset: offset);
Station station = Station.LondonEuston;
List<Station> stationList = new List<Station>() {
Station.Coventry,
Station.WatfordJunction,
Station.MiltonKeynesCentral
};
TimeSpan timeWindow = TimeSpan.FromMinutes(30);
DeparturesBoardWithDetails response = await darwin.Requests.GetFastestDeparturesWithDetailsAsync(station, stationList, timeWindow);
int maxArrivals = 5;
Station station = Station.GlasgowCentral;
TimeSpan timeWindow = TimeSpan.FromMinutes(60);
TimeSpan offset = TimeSpan.FromMinutes(-60);
StationBoard response = await darwin.Requests.GetArrivalBoardAsync(maxArrivals, station, timeWindow, timeOffset: offset);
ServiceDetails service = await darwin.Requests.GetServiceDetailsAsync(response.TrainServices[0].RetailServiceId);
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GNU AGPLv3 License. See LICENSE.txt
for more information.