MALIBAL Logo

How to Test APIs and Web Apps on Linux

Facebook
Twitter
LinkedIn
Reddit
Email

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

Table of Contents

Leave a Reply

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

What are you looking for?

Type in a question or keyword below

Frequently Asked Questions

Do you have any discounts or coupons?

All of our current discounts and deals are listed under the “Promotions” category at the top of the configuration page for each laptop.

 

What is your return policy?

Any laptop purchased from MALIBAL.COM may be returned or exchanged only in accordance with MALIBAL’S return policy in effect on the date of the invoice or acknowledgment. You must contact us directly before you attempt to return a laptop in order to obtain a Return Material Authorization Number for you to include with your return. You must return the laptop to us in its original packaging and condition with all included manuals, discs, accessories etc.

 

Do you offer any military or student discounts?

We don’t offer any military or student discounts at this time.

 

How much is shipping and tax to my state or country?

Shipping costs are determined by cost of notebook and location. Please add a notebook to the cart and then click the, “Estimated Shipping Charges,” link at the bottom of the cart page. Within the US, there are no taxes outside of Nevada. Nevada residents are subject to 8.10% sales tax. For customers outside the US, you will have to pay your local VAT (Value Added Tax) to customs once the notebook arrives in your country.

 

When is my order shipping?

Laptops usually ship out within 5-7 business days after the order is placed. We also offer rush service (1-3 business days) for $50. Once your laptop ships out we will email the tracking number so that you can see the estimated arrival date. Someone will need to be at the address to sign for the package.

 

How do I check the status of my order?

We will send you emails and texts with status updates as your order progresses through the different stages.

 

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. Please note: You cannot change the shipping address on an order.

 

Do you price match?

We do not currently offer any price matching.

 

How do I track my order after it ships?

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

 

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 custom linux laptops, such as our Aon S1 and Aon L1 models, our customers, new articles, latest news, guides, features, and more.