Home » Linux » Creating a lame utility HTTP server in Linux Operating System

Creating a lame utility HTTP server in Linux Operating System

Last updated Oct 4, 2021

In this article, we will discuss the cURL tool in Linux. The cURL tool is used for transferring the data from or to a server. It supports many protocols, and http is one of them. cURL is used to transfer the data from URL. It has so many tricks to offer, such as http post, ftp post, user authentication, proxy support, file transfer, SSL connections, cookies, and similar.

Prerequisites

Besides having a Terminal open, you need to ensure that you have curl installed on your system.

How to do it

We will learn about HTTP GET and POST methods using curl in Linux. Now, we will see examples of GET and POST:

  • GET: The HTTP GET method is used to request a data from a specified resource. The command is the example of HTTP GET and is accepting JSON formatted data:
$ curl -H "Content-Type:application/json" -H "Accept:application/json" -X GET http://host/resource/name

Another example of HTTP GET, which is accepting XML formatted data is as follows:

$ curl -H "Content-Type:application/xml" -H "Accept:application/xml" -X GET http://host/resource/name
  • POST: The HTTP POST method is used to send the data to server. It is used to create as well as update a resource.

A simple POST example is as shown:

$ curl --data "name1=value1&name2=value2" http://host/resource/name

Run the following curl command to upload a file:

$ curl -T "{File,names,separated,by,comma}" http://host/resource/name

How it works

Now we will learn about the options used in the curl command:

  • First, we learned about the GET method in the curl command. We accepted two types of data: JSON and XML. We used the -X option and specified the request. -H specifies the header.
  • Second, we learned about the POST method in the curl command. The --data flag is used for the POST request. In the simple example, we are just posting the simple data and in the next, we are uploading files using the -T option.

Related Posts

Finding binary dependencies in Linux Operating System

In this article, we are going to check the executable. We will find out which string is present in it by using the string command.PrerequisitesBesides having a terminal open, make sure you have a binary present in your directory.Find dependencies First, we...

Capturing network traffic headlessly in Linux Operating System

In this article, we are going to learn how to capture traffic. We are going to capture network traffic with a packet sniffer tool called tcpdump. This tool is used to filter or capture TCP/IP packets that are transferred or received over a network.PrerequisitesBesides...

Mounting network file systems and retrieving files in Linux

In this article, we are going to learn about the mount command. To mount a file system onto the file system tree, use the mount command. This command will instruct the kernel to mount the file system found on a particular device. There is a mount point in the tree for...

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

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

17 − 15 =

Shares