How to Test APIs and Web Apps on Linux

Testing APIs and web applications is a crucial step in the development process. While there are many graphical tools available for this task, sometimes it is more convenient to use the command line interface. In this how-to guide, we will explore how to test APIs and web apps from the command line on Linux.

Using cURL

cURL is a command line tool that is used to transfer data from or to a server, using one of the many supported protocols, including HTTP, HTTPS, FTP, FTPS, SMTP, and more. One of the most common use cases for cURL is testing APIs and web apps.

Step 1: Open Terminal

Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.

Step 2: Install cURL

On Debian/Ubuntu-based distros, run:

sudo apt install curl

On Fedora/RPM-based distros, run:

sudo dnf install curl

On Arch-based distros, run:

sudo pacman -S curl

Step 3: Send GET Request

The simplest way to test an API or web app is to send a GET request. To do this, run:

curl -X GET https://api.example.com/users

This command sends a GET request to the specified URL, which should return a list of users. You can also include headers and request parameters.

Step 4: Send POST Request

If you need to send data to the API or web app, you can use a POST request. To do this, run:

curl -X POST -d “name=value” http://example.com/api

Replace name and value with the data you want to send. This will send a POST request to the specified URL with the data in the body of the request.

Step 5: Send PUT Request

To update existing data in an API or web app, you can use a PUT request. To do this, run:

curl -X PUT -d “name=value” http://example.com/api/id

Replace id with the ID of the data you want to update. This will send a PUT request to the specified URL with the data in the body of the request.

Step 6: Send DELETE Request

To delete data from an API or web app, you can use a DELETE request. To do this, run:

curl -X DELETE http://example.com/api/id

Replace id with the ID of the data you want to delete. This will send a DELETE request to the specified URL.

Step 7: View Response Headers

If you want to view the response headers of a request, run:

curl -I http://example.com/api

This will send a HEAD request to the specified URL and display the response headers.

Step 8: Save Response

To save the response from a request to a file, run:

curl -o filename http://example.com/api

Replace filename with the name you want to give to the file. This will save the response to the specified file.

In conclusion, cURL is a powerful tool that can be used to test APIs and web apps from the command line on Linux. With the commands we’ve shown here, you can easily send GET, POST, PUT, and DELETE requests, view response headers, and save responses to files.

Using HTTPie

HTTPie is another command line tool that is used for testing APIs and web apps. It is similar to cURL but has a more user-friendly interface.

Step 1: Open Terminal

Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.

Step 2: Install HTTPie

On Debian/Ubuntu-based distros:

sudo apt install httpie

On Fedora/RPM-based distros:

sudo dnf install httpie

On Arch-based distros:

sudo pacman -S httpie

Step 3: Test GET Request

To test a GET request, we can simply use the http command followed by the URL of the API or web app we want to test.

For example, to test the GET request for the GitHub API, run:

http https://api.github.com/users/github

This will return the user information for the GitHub user.

Step 4: Test POST Request

To test a POST request, we need to specify the data we want to send in the request. We can do this by using the -d flag followed by the data in JSON format.

For example, to test the POST request for the JSONPlaceholder API, run:

http POST https://jsonplaceholder.typicode.com/posts \
userId=1 \
title=”foo” \
body=”bar”

This will create a new post with the specified data.

Step 5: Test Authentication

To test authentication, we need to use the –auth flag followed by the authentication credentials.

For example, to test authentication for the GitHub API, run:

http –auth user:password https://api.github.com/user

This will return the user information for the authenticated user.

Step 6: Test Headers

To test headers, we can use the -h flag followed by the headers we want to send.

For example, to test headers for the GitHub API, run:

http https://api.github.com/user \
“Authorization: token <token>”

This will return the user information for the user authenticated with the specified token.

Step 7: Test Cookies

To test cookies, we can use the –session flag followed by the name of the cookie session.

For example, to test cookies for the JSONPlaceholder API, run:

http –session=session POST https://jsonplaceholder.typicode.com/posts \
userId=1 \
title=”foo” \
body=”bar”

This will create a new post with the specified data and store the session cookies in the specified session.

In conclusion, HTTPie is a powerful command line tool for testing APIs and web apps from the command line on Linux. With its simple syntax and powerful features, it is a great alternative to using a web browser or a complex testing framework.

Using wget

wget is a command line tool that is used for retrieving files from the web. While it is not specifically designed for testing APIs and web apps, it can be used for this purpose in some cases. To test a REST API with wget, run:

wget -qO- https://api.example.com/users

This command sends a GET request to the specified URL and prints the response to the console. You can also include headers and request parameters. For example:

wget –header=’Content-Type: application/json’ –post-data='{“name”: “John”, “age”: 30}’ https://api.example.com/users

This command sends a POST request to create a new user with the specified name and age.

Conclusion

In conclusion, testing APIs and web apps from the command line on Linux can be a powerful and efficient way to ensure that your application is working as expected. The tools we have discussed here, cURL, HTTPie, and wget, are just a few examples of the many options available. Choose the tool that best fits your needs and get testing!

Please Leave Feedback and Corrections in the Comments

More to Explore

How to Dual Boot Linux and Windows

Dual-booting Linux with Windows, starting with an existing Windows installation, is a popular setup for those who need the versatility of both operating systems. This guide assumes you have already installed Windows and wish to add Linux for a dual-boot setup. If you are starting with an existing Linux installation,

Read More »

How to Dual Boot Windows and Linux

Dual-booting Windows with Linux, starting with an existing Linux installation, requires careful planning and execution. This guide assumes you have already installed Linux and wish to add Windows for a dual-boot setup. If you are starting with an existing Windows installation, then use this guide: How to Dual Boot Linux

Read More »

Table of Contents

Leave a Reply

Availability

We wish to inform our valued customers that, due to significant business growth and existing supply chain constraints, our laptop inventory is expected to be sold out this holiday season.

To secure a laptop for your personal or professional needs in anticipation of Christmas, we recommend placing your order at your earliest convenience.

Upon order placement, the estimated delivery date will be clearly indicated on the cart page, assuring the receipt of your purchase well ahead of the holiday festivities.

We appreciate your understanding and are dedicated to serving you with excellence.

What are you looking for?

Type in a question or keyword below

Frequently Asked Questions

Why are your prices so high?

Our pricing reflects the quality and class of our products. When you compare our Aon S1 laptop with similar models like the Dell XPS 13, Lenovo Thinkpad X1, and MacBook Pro, you’ll find our prices competitive. The Aon S1 stands out for its superior weight-to-performance ratio, user-upgradeability, serviceability, customizability, and support.

We also differentiate ourselves by building our laptops to order in the United States, allowing for a wider range of customization options than manufacturers like Dell, Lenovo, and Apple, all of whom conduct their final assembly in China. This approach does come at a higher cost, but it’s a key factor in our unique offering.

Our commitment to U.S.-based manufacturing not only supports local industry but also enables us to offer a level of customization unparalleled by our competitors. For instance, our Aon S1 offers 24,192 distinct configurations, and the Aon L1 boasts 32,256 possibilities, far exceeding the options provided by even the largest competitors, whose assembly processes in China limit their ability to offer such extensive customization.

Read More

Are all the parts soldered to the motherboard?

In many modern laptops, especially thin and light models (like Apple’s MacBook Air or Pro, Dell’s XPS 13, or many of Lenovo’s ThinkPad X1 Carbon models), the memory, storage, battery, and wireless module are often soldered directly onto the motherboard. This is done to save space and allow the laptop to be thinner, but it means that the RAM and SSD are not user-upgradeable.

However, as part of our commitment to the Right to Repair Movement, the memory, storage, battery, and wireless module all MALIBAL laptops are user-upgradeable or user-replaceable.

Do any of your laptops support coreboot?

Coreboot is an open-source project aimed at replacing the proprietary BIOS (Basic Input/Output System) firmware found in most computers. BIOS firmware is the first piece of software that runs when a computer is turned on. It initializes the hardware and starts the operating system.

Coreboot is designed to perform only the minimum amount of hardware initialization necessary to load and run a modern 32-bit or 64-bit operating system. This minimalist approach not only reduces the complexity and potential attack surface of the firmware, but it can also speed up the system boot time significantly.

Coreboot can be used with payloads such as a Linux kernel, SeaBIOS, or UEFI firmware to provide a complete firmware solution. It’s appreciated by users who want to have more control over their hardware, value the transparency and security that come from open-source software, or have specialized requirements.

Coreboot with EDK II is supported on our Aon line of laptops.

Can your laptops be charged or powered via USB-C?

USB-C is revolutionizing the way we charge laptops. As a universal charging standard, USB-C has a number of advantages that make it particularly suited for this task.

First and foremost, it offers high power delivery capability – up to 100 watts – which is sufficient to charge even power-hungry laptops. This eliminates the need for proprietary laptop chargers and allows for charging via common adapters, power banks, or even other laptops.

Additionally, USB-C is a reversible connector, meaning it can be inserted either way, making it more user-friendly.

It also supports data transfer and display output, allowing for a single cable to provide power, transfer data, and connect to external monitors.

All MALIBAL laptops can be powered via the Thunderbolt 4 port.

Who is MALIBAL?
MALIBAL is an innovative technology company that produces high-performance, custom linux laptops for developers and content creators; mobile workstations for engineers, scientists, video editors, 3D modelers, and animators; and mobile servers for enterprise applications. On our site, you will find information about the best linux laptops, such as our Aon S1 and Aon L1 models, our customers, new articles, latest news, guides, features, and more.
How do I get a quote?

If you need a quote for any reason, e.g., to submit to accounting for approval, before ordering, simply add the laptop(s) you want to purchase to the Cart, then click Checkout, and on the checkout page, click Convert Cart to Quote. We will email you a PDF of the quote with a link to make payment once you are ready to complete the order.

How do I cancel an order?

You may cancel an order any time up until it ships. After it ships, you will not be able to cancel it, but will instead have to use our return policy in order to return the laptop for a refund. To cancel an order, simply open a sales ticket or sales chat and give the representative your order information, and they will cancel the order for you and send you confirmation via email and text.

 

How do I make a change to my order?

You may make changes to your order up until it ships. To modify an order, simply open a sales ticket or sales chat and give the representative your order information and specify which changes you want to make.

When is my order shipping?

If all parts are in stock, the average build time for laptops is 5-7 business days. This means laptops will ship 5-7 business days after the order is placed. If a component is backordered, it will say which parts are backordered in your order confirmation email.

To see the estimated delivery date of your laptop, please check your order confirmation email for the Estimated Delivery Date. You can also see this information on your My Account > Order Details page. The estimated delivery date is the build time (plus backorder delay, if applicable) plus the shipping time.

Once your laptop ships out, we will email you the tracking information. An adult will need to be at the address to sign for the package when it arrives.

How do I track my order after it ships?

You can view your tracking status via the order details page in your account.

ORDER NOW. SUPPLIES ARE LIMITED. LEARN MORE