How Do You Create a REST API Endpoint?

Problem scenario
You want a REST API endpoint. How do you create a URL that is a proof-of-concept to trigger a Python program?

i. You have installed Python 3. If you are using CentOS/RHEL/Fedora, run this: sudo yum -y install python3
ii. You need a web server installed. If you do not have one, install Apache web server.
iii. You must have PHP installed. To install it, run this command: sudo yum -y install php

1. Create a file in /home/ec2-user/ called with the following content:

# This was adapted from
import logging

logger = logging.getLogger(__name__)

# create a file handler
handler = logging.FileHandler('hello.log')

# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# add the file handler to the logger
logger.addHandler(handler)'Hello from contint')

2. Create a file in /var/www/html/ called good.php with the following content:





   $command = escapeshellcmd('/usr/bin/python3 /home/ec2-user/');
   $output = shell_exec($command);
   echo $output;


Leave a comment

Your email address will not be published. Required fields are marked *