Skip to content
rkz edited this page Apr 9, 2013 · 5 revisions

Data model

Business logic

Code structure

  • The electifs_core module contains all the business logic and is independant from the web interface concerns.
  • electifs.py is the main entry point to the web application (it implements the HTTP server-side logic). Responses are JSON for the REST API, or generated from the templates in the templates directory.
  • Files in the static directory are served as is to the HTTP client.

HTTP interface

From the server point of view, the web application is composed of a single page exposed at URL /.

REST API URLs

Most of the server interaction is controlled via a REST API which exposes routes starting by /api/ and which always return JSON responses.

  • /api/ratings: GET the ratings for a specific course (in admin mode, will return all the ratings; otherwise, only the ratings which have been validated and accepted)
  • /api/post-rating: POST a rating to a course
  • /api/admin/login and /api/admin/logout to switch the admin mode on or off

JSON responses

The JSON responses always follow the same format:

{
    "status": "success|error",
    ["error": {
        "code": "error_code",
        "message": "Error description in full text",
        [additional error information]
    },]
    [additional response data]
}

On success, the HTTP status code is always 200. On error, it is never 200:

  • 404 (not found) if the URL (before the parameters part) references a resource that cannot be found
  • 400 (bad request) if some GET/POST paremeter is missing or has a wrong syntax
  • 412 (precondition failed) if a parameter's value blocks the request

Examples:

/api/get-ratings throws HTTP 404

/api/ratings or /api/ratings?course_id=AAA throw HTTP 400

/api/ratings?course_id=99 throws 412 if no course with ID 99 exists

Clone this wiki locally