A new API can be added to Controller. Follow the steps
All APIs remain in routes.py
. If you want to create an independent API call then it is very easy. An independent API means when you don't want to log the process in the Foundry database. But if you want to create integrated API, means log the process in the Database then there are additional steps to be followed
- Write a python function to be called from API in a separate .py file
eg. sample_api.py
. - Import
sample_api.py
in routes.py - Follow following structure to create api route in routes.py. (This API will be similar to reboot API)
@app.route('/controller/<new_api>', methods=['POST'])
@validate_request
def new_api():
status = <Function from sample.py>()
return(jsonify({'message' : status}), 200)
- It is necessary to apply validate_request decorator, it will authenticate the API request.
- Ensure that your function returns appropriate and meaningful response which will get returned as message to the client