Concept of API and CGI :-

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.

No alt text provided for this image

Now, we have to check connectivity between our servers we can check it by using ping command on command prompt in Windows O.S.

No alt text provided for this image

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.

No alt text provided for this image

In order to enable CGI facility, we have to enable CGI on our web server. But by default, Apache provides us this facility.

No alt text provided for this image

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/

No alt text provided for this image

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"

No alt text provided for this image

2) Use " #!/usr/bin/python3 "

No alt text provided for this image

3) Give content-type

No alt text provided for this image

And Finally we get desired output on the client's browser.

No alt text provided for this image

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.

No alt text provided for this image

But we don't get output due to some reasons.

No alt text provided for this image

>> So to overcome this problem we use subprocess module.

No alt text provided for this image

This prints date on client's server.

No alt text provided for this image

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 !

Like
Reply

Nice informations.. Thanks Virukshali

Like
Reply

To view or add a comment, sign in

More articles by Vrukshali Torawane

Others also viewed

Explore content categories