Porting the bottle.py from local server on to Apache

Apache server can be run locally on a specific port. But when porting the server framework onto apache – a few changes are required. Firstly – the run command is not required. Additionally – an object of bottle may not be required. Therefore, the previous post that explained hosting bottle.py framework on local server will be slightly modified as follows when ported to Apache:

from bottle import Bottle, run, template, get, post, request, response
from bottle import default_app
import json


@get('/yourpath')
@get('/yourpath/')
@get('/yourpath/')
def invoke(api='Invalid-API-Call'):
	apiCalled=api.lower()
	#return template('GET :: Invoking {{qname}}', qname=api-name)
	if(apiCalled == "create-account"):
		returnMessage = "Execute create_account()"
	elif(apiCalled == "modify-account"):
		returnMessage = "Execute modify_account()"
	elif(apiCalled == "delete-account"):
		returnMessage = "Execute delete_account()"
	else:
		returnMessage = '{"Code" : -1, "Message" : "Invalid API Call"}'
	return returnMessage 

@post('/yourpath')
@post('/yourpath/')
@post('/yourpath/')
def invoke(api='Invalid-API-Call'):
	response.content_type = 'application/json'
	apiCalled = api.lower()
	data = request.json #This is unicode text (decoded/dictionary)
	jsonData = json.dumps(data) #Converts to JSON
	if(apiCalled == "create-account"):
		returnMessage = __create_account(jsonData)
	elif(api == "modify-account"):
		returnMessage = __modify_account(jsonData)
	elif(api == "delete-account"):
		returnMessage = __delete_account(jsonData)
	else:
		returnMessage = '{"Code" : -1, "Message" : "Invalid API Call"}' 
	return returnMessage

def __create_account(reqData):
	h = businessHandler(reqData)
	response = h.createAccount()
	return response

def __modify_account(reqData):
	h = businessHandler(reqData)
	response = h.modifyAccount()
	return response

def __delete_account(reqData):
	h = businessHandler(reqData)
	response = h.deleteAccount()
	return response
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s