Skip to content

Add your own REST url

Michael Jolin edited this page Jul 7, 2017 · 5 revisions

To implement your own REST url create the following structure

myproject
  +-- mypackage
  |     +-- app
  |     |     +-- resturls
  |     |     |     +-- firsturl.py
  |     |     |     +-- secondurl.py
  |     +-- api_url.py

Example of api_url.py file

And defined your own class in each file

from cause.api.management.core.database import Database
from cause.api.management.resturls.base import Base


class FirstUrl(Base):
	table_name = 'ssi'
	mapping_method = {
		'GET': 'get',
		'PUT': '',
		'POST': '',
		'DELETE': '',
		'PATCH': '',
	}

	def get(self):
		""" Return all fire safety department
		"""
		with Database() as db:
			return {
				'data': db.execute("SELECT * FROM mytable;")
			}