# api package — Transport Accessibility 0.2 documentation

# api package

## Subpackages

## Submodules

## api.admin module

## api.apps module

class api.apps.ApiConfig(app_name, app_module)

  Bases: `AppConfig`

  default_auto_field = 'django.db.models.BigAutoField'
  name = 'api'

## api.models module

## api.tests module

## api.urls module

## api.views module

### Views

Views serving (mostly JSON) data via HTTP, no actual web pages.

#### Functions

timetable

  Fetches timetables for given routes on api/timetable/

data

  Serves api/models/ GET: Fetches models given their primary keys PUT: Creates new model objects or updates them with complete representations. If object with the given primary keys exist, they will be deleted and replaced. PATCH: Updates models, identified by their primary keys without deleting them. Can be incomplete representations. DELETE: Deletes models, identified by their primary keys.

api.views.data(request)

  Handle database requests from the frontend. Using Http semantics to specify what to do with the data.

  ### Request

  PUT

    Create a new object if no object with the given primary key exists in the database or delete and replace an existing object. Body must be a json dict of lists of fully specified, valid models. Primary keys can be omitted and will be ignored if the element does not exist in the database. If primary keys are given, the elements are deleted and replaced. Note that if there is an error in creating the new object, the object to replace will still probably already have been deleted. Successful response is 200 with a list of primary keys of the created and replaced objects.

  PATCH

    Modify an existing objects given the instructions in the body. Body must be a json dict of lists of fields to change and their valid values existing objects in the database, identified by their valid primary keys. Responds 400 if any of the primary keys given does not exist. Successful response is 200 with a list of the primary keys of the modified objects.

  GET

    Return json of models identified by primary keys. Responds 400 if any of the requested pks does not exist.

  DELETE

    Delete models with given primary keys if they exist. Responds 400 if any of the primary keys given does not exist in the database. Successful response is 200 and the number of deleted models.

api.views.timetable(request)

  Lookup timetable data for given routes.

  ### Request

  GET: Find timetables for all routes passed via GET. Successful response is a Json representation of a dict of timetables in the following form:

      {
          route_id (from GET): {
              'stop_sequence': [stop_ids for all stops the route server, in order],
              'stop_times': {
          stop_id (from stop_sequence): [str in the format HH:MM representing stop times]
          }
      }

## Module contents