Creating a lame utility HTTP server in Linux Operating System

March 5, 2021

Comments

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.
Satish Kumar

Satish Kumar

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.

Related Posts

Encrypting/decrypting files from a script in Linux

In this article, we are going to learn about OpenSSL. In this section, we are going encrypt and decrypt messages and files using OpenSSL.Prerequisites Besides having a terminal open, you need to have a basic knowledge of encoding and decoding schemes....

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...

0 Comments

0 Comments

Submit a Comment

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

13 + 4 =

News & Updates

Join Our Newsletter