Skip to content

A powerful and user-friendly C# wrapper for the National Rail Darwin OpenLDBWS API.

License

Notifications You must be signed in to change notification settings

rhys-wootton-cackett/Darwin.Net

Repository files navigation


Logo

Darwin.Net

A powerful and user-friendly C# wrapper for the National Rail Darwin OpenLDBWS API.
Explore the docs »

About The Project

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.

(back to top)

Getting Started

Build Locally

To get a local copy built, follow these simple example steps.

  1. Obtain an API key from National Rail Enquiries
  2. Clone the repository
    git clone https://github.com/rhys-wootton/Darwin.Net.git
  3. 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>
  4. Build the project

(back to top)

Usage

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:

Get up to 10 arrivals at a station for the next 90 minutes
int maxArrivals = 10;
Station station = Station.LondonBridge;
TimeSpan timeWindow = TimeSpan.FromMinutes(90);

StationBoard response = await darwin.Requests.GetArrivalBoardAsync(maxArrivals, station, timeWindow);
Get up to 5 departures at a station within the last hour with specific calling points
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);
Get the next fastest services from a station to a list of station within the next 30 minutes
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);
Get specific services details
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);

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the GNU AGPLv3 License. See LICENSE.txt for more information.

(back to top)