Concept of API and CGI :-
API :- Application Programming Interface
CGI :- Common Gateway Interface
So our task is : There are two operating systems one is RedHat 8 Linux (known as server) and other is Windows (known as client). We had made a program file in our server and we have to execute the program file on our client's browser without logging into server. How can we do this?
One way is we can do it via Networking or Remote Login.
Firstly, we have to get I.P. of our server. We use ifconfig command to get I.P. address.
Now, we have to check connectivity between our servers we can check it by using ping command on command prompt in Windows O.S.
I.P. is just a address to reach somewhere.
Now, since we got connectivity between the two servers now we can try to do our task. Now, our client sent a request to server that we want run the program file on client's browser. The program accepts the request from user on behalf of server without giving password or login-name and runs the program file for us.
The program that accepts the request on behalf of server and acts as an interface is commonly known as COMMON GATEWAY INTERFACE (CGI).
The program that gives CGI facility is known as WEB SERVICES. The system to run web services is known as WEB SERVER.
So here, we use Apache as a web server. Apache provides us a software httpd to configure web server.
In order to enable CGI facility, we have to enable CGI on our web server. But by default, Apache provides us this facility.
To run our program file we have to save our program file myfile.py in that folder which provides us the CGI facility .i.e., /var/www/cgi-bin/
If we try to run our myfile.py on client's browser it shows error.
In order to overcome this error we have to follow the following steps :-
1) Use command "chmod +x myfile.py"
2) Use " #!/usr/bin/python3 "
3) Give content-type
And Finally we get desired output on the client's browser.
WEB PAGE :- The page that shows code.
WEB APP :- The page that runs code.
WEB CLIENT :- Chrome/ Firefox etc. are known as web clients.
Also, in this task, we use python as language so python is known as SERVER-SIDE LANGUAGE.
>> We use os module to run date command.
But we don't get output due to some reasons.
>> So to overcome this problem we use subprocess module.
This prints date on client's server.
Now lets understand API :-
In the URL, we provide a PROGRAM name, so the client can interfere in the server by using program known as INTERFACE and run APPLICATION typically known as API.
CGI helps the client to come inside the server and after the client enters it all depends on API, which program to run.
Hopefully this would be helpful.
Thank you :)
Thanks Vrukshali , for making such type of content about API and CGI its really helps us to understand .keep going !
Nice informations.. Thanks Virukshali