bin.controller module

HTTP interface and processing

Various HTTP routes the external world uses to communicate with the application.

bin.controller.assets(filepath)

Get a static css/js/media file that is stored in the filesystem.

This route exists for developers of bin who wish to run the service with minimum system requirements. In production, we suggest you use a web server to deliver the static content.

bin.controller.delete_snippet(snippetid, ext=None)

Delete a snippet

Parameters

Authorization – (header) required “Authorization: Token <ADMIN_TOKEN>” the “admin” token

Raises
  • HTTPError – code 400 when the Authorization (token) is missing

  • HTTPError – code 404 when the snippet is not found

  • HTTPError – code 401 when the token is incorrect

bin.controller.get_html(snippetid, ext=None)

Get a snippet in a beautiful html page

Parameters
  • snippetid – (path) required snippet id

  • ext – (path) optional language file extension, used to determine the highlight backend

  • token – (query) optional the “admin” token

Raises

HTTPError – code 404 when the snippet is not found

bin.controller.get_new_form()

Get the browser-friendly html form to easily post a new snippet

Parameters
  • lang – (query) optional lang that is selected in the lang selection instead of the configured default

  • parentid – (query) optional ‘parent’ snippet to duplicate the code from

Raises

HTTPError – code 404 when the ‘parent’ snippet is not found

bin.controller.get_raw(snippetid, ext=None)

Get a snippet in plain text without code hightlight

Parameters
  • snippetid – (path) required snippet id

  • ext – (path) ignored parameter

bin.controller.healthcheck()

Get a dummy string ‘alive’ to ensure the server is responding

bin.controller.post_new()

Post a new snippet and redirect the user to the generated unique URL for the snippet.

Parameters
  • code – (form) required snippet text, can alternativaly be sent as a Multi-Part utf-8 file

  • lang – (form) optional language

  • maxusage – (form) optional maximum download of the snippet before it is deleted

  • lifetime – (form) optional time (defined in seconds) the snippet is keep in the database before it is deleted

  • parentid – (form) optional snippet id this new snippet is a duplicate of

  • token – (form) optional the “admin” token allows you to delete your snippet

Raises
  • HTTPError – code 411 when the Content-Length http header is missing

  • HTTPError – code 413 when the http request is too large (mostly because the snippet is too long)

  • HTTPError – code 400 with a sensible status when the form processing fails

bin.controller.report()

Report a problematic snippet to the system administrator.

Parameters
  • snippetid – (form) the reported snippet

  • name – (form) the name of the user reporting the problem

Raises
  • HTTPError – code 400 when any of the snippetid or the name is missing

  • HTTPError – code 404 when the reported snippet is not found