2

I'm new to servers setup, I'm trying to understand - do I need Apache or smth to handle HTTP requests?

For example, I'm getting GET /api request, and I want to send a response. Can I do it without Apache? For example, just create BaseHTTPRequestHandler Python class and redefine do_GET

class MyHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/api':
            some_function()
        else:
            another_function()
            
        self.send_response(200)

and use some code like this:

httpd = socketserver.TCPServer(("", 8080), MyHandler)
httpd.serve_forever()

So can I do it without Apache? If yes, why do people need Apache?

PS: idk does it matter, but I want to use certificate authentication on my server.

PSS: to be clear - my company just "rents" an application, so I don't need to write app code. I need to handle some POST requests from this application by my server and then send some POST requests from my server to this application (to its server). So it is possible to do it with clear Linux and python script that I've described in the question? Or do I need to install some HTTP server (like Apache)?

Sviatoslav
  • 37
  • 7

1 Answers1

3

You probably need some HTTP server. There are many alternatives (operating system specific) and you might find one coded in Python.

On Linux, see also lighttpd and libonion. BTW, you could call libonion from Python code by embedding it. And you could code in Guile your web application.

P.S.: idk does it matter, but I want to use certificate authentication on my server.

This requires HTTPS and probably OpenSSL.

. I need to handle some POST requests from this application by my server

You probably should use some HTTP client library. Python got one, but you might also use libcurl.

reason in terms of HTTP or HTTPS protocol interactions (requests and replies)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 1
    To be clear - my company just "rents" an application, so I don't need to write app code. I need to handle some POST requests from this application by my server and then send some POST requests from my server to this application. So it is impossible to do it with clear Linux and python script that I've described in the question? I need to install some HTTP server (like Apache)? – Sviatoslav Aug 13 '20 at 09:59
  • 2
    You should add all relevant information to the question. The comments of an answer are not read by everyone. – Klaus D. Aug 13 '20 at 10:01