Coder Social home page Coder Social logo

cercanias-api's Introduction

Cercanias API

Access Renfe's Cercanias information through a HTTP REST API.

Build Status

Requirements

The cercanias-api project has the following requirements:

  • PHP 5.3+
  • A HTTP server (Apache, nginx, ...)

Installation

The easiest way to install it is to clone the repository:

git clone https://github.com/rmhdev/cercanias-api

After that you'll need to install Composer:

curl -sS https://getcomposer.org/installer | php

Finally, you'll be able to retrieve all the dependencies:

php ./composer.phar install

Configure the server

This project is built using Silex. The official docs will give you more information about how to configure your server. Make sure that:

  • the document root points to the cercanias-api/web/ directory.
  • folders in cercanias-api/var/ must be writable by the web server.

Play with the API

If you are using PHP 5.4+, its built-in web server will help you to play with this project:

php -S localhost:8080 -t web web/index.php

Easy, right? Just open a browser and enter http://localhost:8080

API requests

Index urls:

GET -> http://localhost:8080

Retrieve all the routes:

GET -> http://localhost:8080/route

Retrieve the stations from a route:

GET -> http://localhost:8080/route/{routeId}

Retrieve the timetable for a query:

GET -> http://localhost:8080/timetable/{routeId}/{departureId}/{destinationId}/{date}

Information about the parameters:

  • {routeId}: (string) route id. For example, Madrid is 10.
  • {departureId} and {destinationId}: (string) station id. For example, Oviedo is 15211.
  • {date}: (string). Read more about accepted date formats. For example, 2014-07-25, today, tomorrow, etc.

API responses

Index url

GET -> http://localhost:8080
{
    "routes_url": "http://localhost:8080/route",
    "route_url": "http://localhost:8080/route/{routeId}",
    "timetable_url": "http://localhost:8080/timetable/{routeId}/{fromId}/{toId}/{date}"
}

Routes url

GET -> http://localhost:8080/route
{
    "routes": [
        {
            "id": 20,
            "name": "Asturias",
            "url": "http://localhost:8080/route/20"
        },
        // ...
    ]
}

Route url

GET -> http://localhost:8080/route/61
{
    "id": "61",
    "name": "San Sebastián",
    "url": "http://localhost:8080/route/61",
    "stations": [
        {
            "id": "11409",
            "name": "Alegia de Oria",
            "route_id": "61"
        },
        // ...
    ]
}

Timetable url

GET -> http://localhost:8080/timetable/61/11305/11600/2014-07-23
{
    "departure": {
        "id": "11305",
        "name": "Brincola",
        "route_id": "61"
    },
    "destination": {
        "id": "11600",
        "name": "Irun",
        "route_id": "61"
    },
    "transfer": false,
    "route": {
        "id": "61",
        "name": "San Sebastián",
        "url": "http://localhost:8080/route/61"
    },
    "date": "2014-07-23T00:00:00+02:00",
    "return_url": "http://localhost:8080/timetable/61/11600/11305/2014-07-23",
    "trips": [
        {
            "line": "c1",
            "departure": "2014-07-23T05:53:00+02:00",
            "arrival": "2014-07-23T07:23:00+02:00",
            "transfers": []
        },
        // ...
    ]
}

Similar response, but with transfer trains:

GET -> http://localhost:8080/timetable/50/79600/71802/2014-07-23
{
    "departure": {
        "id": "79600",
        "name": "Arenys de Mar",
        "route_id": "50"
    },
    "destination": {
        "id": "71802",
        "name": "Barcelona-Passeig de Gràcia",
        "route_id": "50"
    },
    "transfer": {
        "id": "",
        "name": "Barcelona-El Clot-Aragò",
        "route_id": "50"
    },
    "route": {
        "id": "50",
        "name": "Barcelona",
        "url": "http://localhost:8080/route/50"
    },
    "date": "2014-07-23T00:00:00+02:00",
    "return_url": "http://localhost:8080/timetable/50/71802/79600/2014-07-23",
    "trips": [
        {
            "line": "r1",
            "departure": "2014-07-23T05:59:00+02:00",
            "arrival": "2014-07-23T06:49:00+02:00",
            "transfers": [
                {
                    "line": "r2",
                    "departure": "2014-07-23T06:56:00+02:00",
                    "arrival": "2014-07-23T07:01:00+02:00"
                },
                {
                    "line": "r2",
                    "departure": "2014-07-23T07:10:00+02:00",
                    "arrival": "2014-07-23T07:15:00+02:00"
                }
            ]
        },
        // ...
    ]
}

Copyright and license

Code and documentation copyright 2014 Rober Martín H. Code released under MIT license. Docs released under Creative Commons CC BY 4.0.

Author

My name is Rober Martín H (@rmhdev). I'm a developer from Donostia / San Sebastián.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.