Entrepreneur, Law & Policy Analyst helping clients w/ strategic planning, communications interoperability, Software Developer, Scotch Enthusiast.
2397 stories

HTTPie, a Human-Friendly cURL-Like Tool

1 Share

cURL is a commonly used command-line tool for making HTTP requests. In this tutorial, we'll have a look at HTTPie, a command-line tool for making HTTP requests in a human-friendly way. HTTPie uses commands with simple and natural syntax and displays the output in a presentable manner. 

From the official docs:

HTTPie (pronounced aitch-tee-tee-pie) is a command line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible. It provides a simple http command that allows for sending arbitrary HTTP requests using a simple and natural syntax, and displays colorized output. HTTPie can be used for testing, debugging, and generally interacting with HTTP servers.

Getting Started

In order to get started with HTTPie on an Ubuntu machine, you need to install the package using apt-get.

Once it's installed, you should have HTTPie on your system. Try to make a GET request to any website using HTTPie:

The above query gives the following response:

HTTP Response

That looks as if HTTPie is installed and working on your system. If you look closely, the colored output of the above command shows that the URL has been moved permanently to https://tutsplus.com. Hence, to do a GET request query on tutsplus, modify the query:

The above query would return the HTML output of the GET request on the URL https://tutsplus.com

As seen from the above query, the only information HTTPie needs to perform a request is the URL.

Performing Basic Requests Using HTTPie

Before diving deep into HTTPie commands, we'll have a look at how to perform the basic requests using HTTPie. We'll be making use of json-server to have a dummy server up and running for making requests. To get started with json-server, install the server using npm.

Create a file called index.js which will create some random data for our dummy server.

Run the json server using the index.js file.

Now the server should be up and running at http://localhost:3000/.

GET Request Using HTTPie

By default if a URL is given to HTTPie, it assumes the request type to be GET and performs accordingly. Here is an example of a GET request:

The above request displays the following output:

POST Request Using HTTPie

To perform a POST request using HTTPie, we need to add the POST keyword along with the data to be posted to the URL. Here is an example:

The command would display the following output on the terminal screen:

Try doing a GET request using HTTPie, and you should see the newly posted data in the response.

Submitting Forms Using HTTPie

Submitting a form is another request that is commonly performed by a user. With HTTPie, it becomes quite a bit easier to submit a form over a URL by specifying the form option as shown:

When the above command is executed, the Content-Type is automatically set to application/x-www-form-urlencoded; charset=utf-8, hence you don't need to set it explicitly.

Handling HTTP Redirect

As you may have noticed in our earlier example, by default HTTPie does not handle HTTP redirects. When we tried to do a GET request on www.tutsplus.com, it showed a message stating the URL had been moved. If you want HTTPie to handle redirects, you need to add an option called follow to the request command.

The above HTTPie query would handle HTTP redirects, if any.

Download Files Using HTTPie

HTTPie provides a feature to download files from a server, similar to the wget command. In order to download the file, you need to specify a download option along with the URL.

The above command would display a response as shown below:

Handling Authentication

Accessing a web service URL would require some or other kind of authentication. HTTPie supports most of the commonly used authentication mechanisms. By default, HTTPie supports basic authentication, so you only need to pass in the username and password to the request with the -a option. 

To use a digest authentication, you'll need to pass in the authentication mechanism name using the -A option.

Customizing the Response Display

When we make a request to a URL, all the data along with the header information is displayed in the terminal. HTTPie provides an option to customize the output response. You can print the individual header and body information by specifying the --header and --body option along with the request.

The above command would print the header information as shown:

Now, if you try the HTTP request along with the --body option, it should only print the body portion.

The above command would print the following output:

Maintaining Sessions

While using HTTPie, each request is independent of other requests. We can keep sessions in case we want to persist the session for other HTTP requests. In order to maintain a session, all we need to do is create a named session as shown:

The above command would create a session called roy which can be used for other requests by using the session name. Here is an example which uses the session roy:

Auto Complete Using HTTP Prompt

It might be difficult to remember all commands related to HTTPie. The http-prompt toolkit provides an auto complete feature which can be used along with HTTPie. To get started with http-prompt, install it using pip:

To start a session, invoke http-prompt with the server URL which we'll be querying. Restart the json-server that we installed and invoke the http-prompt as shown:

Type in a few letters of HTTP and the auto complete should show up.

A demo of the autocomplete

Type in httpie and it should display the URL we are querying.

All the HTTPie request commands should be working in the http-prompt. Try typing in GET and it should pop up in the auto complete. On entering the GET command, the following response should be displayed.

The response of a GET command

Wrapping It Up

In this tutorial, we saw how to get started with HTTPie, a more human-friendly cURL alternative. We saw how to do the basic request operations like GET and POST using HTTPie and some other features. For in-depth information on using HTTPie, do have a look at the official documentation. Also check out the official documentation for http-prompt. Do let us know your thoughts in the comments below.

Read the whole story
1 day ago
Baltimore, MD
Share this story

Every Move You Make, We’ll Be Watching You

1 Share

Every now and again, my work feels like play and I find myself chortling. Thanks to Dave Ries for turning me on to the Dutch website ClickClickClick. Make sure to turn your audio on, as the site asks you to do. You may feel a bit stoned out (a long ago sensation) by this site – so pick your moment to visit it.

As described by a Naked Security post, the point of the website is that the technology of today can track EVERY move we make and every click we take. There is quite a running audio commentary about everything you do. It teased me about logging in during working hours (hey, this is my work buddy!). And it protested if I moved my cursor to another monitor.

Are you still there? You haven't been around for quite some time now. I'm thinking, do you still like me?

The audio commentary is made in a jaunty Dutch accent – the site was created by Dutch media company VPRO and the Amsterdam-based interactive design company Studio Moniker.

It's a simple site – a white screen with a big green button labelled "Button" in the middle – and it has a simple mission: to observe and comment on everything that visitors do on the site, in great detail, and to thereby remind visitors about just how closely our online behavior is monitored.

Subject! Stay focused! …inactive… waiting possibly for something to happen? Come on, subject. You were being so great. Do something. Moving around a lot now. Curious and energetic. Interesting.

You may be my favorite visitor.

Studio Monkier designer Roel Wouters told news.com that ClickClickClick was designed to remind people about the serious themes of big data and privacy.

There's nothing unique about ClickClickClick's tracking. What is unique is that it's upfront about it, letting us see the granularity of that tracking in an ongoing log that streams on-screen with notations including where on the screen you moved, whether you zigzagged or moved straight, how many pixels, how long you were inactive and the like. The site actually tracks the possible "achievements" you can make. I made it up to 39% before I remembered that I had paying work to do.

Unusual behavior… Subject has been gone for 10 minutes… Very slow. Boring like hell.

Go play and have fun. I did decline to let the site see me by turning on my webcam. That was just too creepy, even my mesmerized, zoned out state!

E-mail: snelson@senseient.com Phone: 703-359-0700
Digital Forensics/Information Security/Information Technology

Read the whole story
1 day ago
Baltimore, MD
Share this story

[Orin Kerr] A reply to Professor Lessig on the electoral college

1 Comment

A few days ago, I critiqued an argument by Professor Lawrence Lessig that electors should name Hillary Clinton president of the United States because she won the popular vote. Professor Lessig has graciously responded to my post, and I thought I would flag his response and offer a reply.

As Lessig’s response clarifies, his proposal is that electors should exercise their best judgment about who should be president in light of our commitment to weighing the votes of citizens equally:

My argument is that an elector should recognize just how fundamental the popular vote is to our understanding of the modern presidency. And more precisely, how important it now is within our constitutional tradition that we weigh the votes of citizens equally. That recognition should in turn lead an elector to avoid casting her vote in away that defeats a popular election.

In Lessig’s view, electors should approach the job of ascertaining the best pick for the presidency with a theory of democracy, that of equal vote weight, in mind. That should lead them to favor whoever won the most votes who was also a reasonable choice.

In response to my concern that Lessig’s proposal would unfairly change the rules after the vote took place, Lessig writes:

All this, Orin insists, however, should be “announced beforehand so the candidates can try to win under the understood rules.” Of course that’s right. But Orin agreed the electors exercise judgment. And the principle of one person, one vote was not announced in an op-ed last week. I believe we should apply the rules that should have been clear on January 1, 2016. Those rules include the idea that my vote should not count different merely because of where I live.

I really appreciate Lessig’s clarification. Here are two thoughts in response.

First, I continue to think there’s a considerable clash between the originalist idea of electors exercising their independent judgment and the modern idea of electors following the nationwide majority vote. Lessig attempts to reconcile them by describing the originalist standard as a view that electors should follow “reasons and inducements which were proper,” quoting Federalist 68. The importance of a nationwide majority vote is so clear, Lessig suggests, that it is “proper” for electors to be “induced” by that “reason.”

But I think Federalist 68 articulates a different idea. The power to pick the president is not to be given to the people, it says, but rather “to men chosen by the people for the special purpose” of electing the president. These electors should be wise and judicious men capable of deliberating over the best choice and exercising the careful judgment needed to pick the best president based on all the relevant information. They should be, the essay explains,

men most capable of analyzing the qualities adapted to the station, and acting under circumstances favorable to deliberation, and to a judicious combination of all the reasons and inducements which were proper to govern their choice. A small number of persons, selected by their fellow-citizens from the general mass, will be most likely to possess the information and discernment requisite to such complicated investigations.

This sounds really different from just following national vote totals. If electors are just following the national vote totals, then they have no “complicated investigation” to conduct nor any need to “analyze the qualities” of nominees “under circumstances favorable to deliberation.” They just have to wait for the national vote count and then pick the candidate with the highest number. That requires no judgment. It wouldn’t even matter who the electors are; you could replace the lot of them with a calculator. Given that, there does seem to be a significant clash between the originalist idea of electors exercising independent judgment and the newer idea of electors deferring to national vote counts.

I think there is a broader difficulty with Lessig’s argument. At its core, Lessig’s view is that there is a “constitutional tradition that we weigh the votes of citizens equally” that should govern election results. Just as a descriptive matter, though, that factual claim strikes me as too broad. A line of important Supreme Court cases applies the principle of “one person, one vote” in some contexts. That’s a big deal. At the same time, our constitutional tradition recognizes, and in some contexts directly embraces, the unequal weighing of votes. For better or worse, our constitutional tradition reflects a mix of equality and inequality.

Consider the constitutional text about the electoral college. Article II, Section 1 states that “[e]ach state shall appoint, in such manner as the Legislature thereof may direct, a number of electors, equal to the whole number of Senators and Representatives to which the State may be entitled in the Congress.” That’s strikingly unequal. Small states get more electoral college power per voter than do large states.

If we’re identifying our constitutional tradition, then I think we need to be more specific. The question is not just whether there is a tradition of equal weighing of votes in some areas, but whether that tradition has been understood to govern the specific question of how electors vote for president.

It seems to me that the answer to that question is clearly “no.” For better or worse, our understood tradition is the weird winner-take-all, state-by-state system in which the popular vote just doesn’t matter. That’s what the campaigns assume the rules will be. That’s what the media assumes the rules will be. And that’s what voters assume the rules will be, too.

Think of what you saw when you turned on the TV on the night of Nov. 8. The talking heads presented the election as a race to 270 electoral college votes based on the winner-take-all state votes, not the nationwide popular vote. The networks called states for Donald Trump or Clinton accordingly. After Trump reached 270 votes based on those assumptions, the networks called the election for Trump. Clinton conceded defeat.

Imagine you had turned on the TV that night and the networks announced that they couldn’t call any states because they didn’t know yet who won the nationwide popular vote. You would think it a bizarre error, or maybe some kind of joke. It would conflict with settled understandings of how presidential elections work.

Lessig argues that it should have been clear, before the election, that our constitutional tradition rejects that understanding. But the word “should” is doing a lot of work here. It’s a normative argument for change. It urges us to rethink the electoral college and replace our existing tradition of inequality with a new tradition of equality. I’m certainly open to that going forward. But it’s a call for a big shift in how we think about presidential elections, not just a recognition of a consensus view held before Nov. 8.

That’s my sense, at least. Thanks again to Professor Lessig for the excellent exchange.

Read the whole story
1 day ago
Required reading (all 4 of the articles/responses, this is the last) - Especially if you plan on making any "They should(or shouldn't) change the electoral college" arguments at your next holiday party. These gentleman are a fine example of intellectual exchange, and the output is great reading on a tricky topic.
Baltimore, MD
Share this story

Announcing auto-shutdown for VMs using Azure Resource Manager

1 Comment and 4 Shares

We are excited to announce you can set any ARM-based Virtual Machines to auto-shutdown with a few simple clicks!
This was a feature originally available only to VMs in Azure DevTest Labs: your self-service sandbox environment in Azure to quickly create Dev/Test environments while minimizing waste and controlling costs. In case you haven't heard it before, the goal for this service is to solve the problems that IT and development teams have been facing: delays in getting a working environment, time-consuming environment configuration, production fidelity issues, and high maintenance cost. It has been helping our customers to quickly get “ready to test” with a worry-free self-service environment.
The reusable templates in the DevTest Labs can be used everywhere once created. The public APIs, PowerShell cmdlets and VSTS extensions make it super easy to integrate you Dev/Test environments from labs to your release pipeline. In addition to the Dev/Test scenario, Azure DevTest Labs can also be used in other scenarios like training and hackathon. For more information about its value propositions, please check out our GA announcement blog post. If you are interested in how DevTest Labs can help for training, check out this article to use Azure DevTest Labs for training.
In the past months, we’ve been very happy to see that auto-shutdown is the #1 policy used by DevTest Labs customers. On the other hand, we also learned from quite a few customers that they have their centrally managed Dev/Test workloads already running in Azure and simply want to set auto-shutdown for those VMs. Since those workloads have already been provisioned and managed centrally, self-service is not really needed. It’s a little bit overkill for them to create a DevTest lab in this case just for the auto-shutdown settings. That’s why we make this popular feature, VM auto-shutdown, available to all the ARM-based Azure VMs.
With this feature, setting auto-shutdown can’t be easier:

  • Go to your VM blade in Azure portal.
  • Click Auto-shutdown in the resource menu on the left-side.
  • You will see an auto-shutdown settings page expanded, where you can specify the auto-shutdown time and time zone. You can also configure to send notification to your webhook URL 15 minutes before auto-shutdown. This post illustrates how you can set up an Azure logic app to send auto-shutdown notification.

    Set auto-shutdown for any ARM-based Azure VMs

To learn more about this feature or see what's more Azure DevTest Labs can do for you, please check out our announcement on the Azure DevTest Labs team blog.

To get latest information on the service releases or our thoughts on the DevTest Labs, please subscribe to the team blog’s RSS feed and our Service Updates.

There are still a lot of things in our roadmap that we can’t wait to build and ship to our customers. Your opinions are valuable for us to deliver the right solutions for your problems. We welcome ideas and suggestions on what DevTest Labs should support, so please do not hesitate to create an idea at the DevTest Labs feedback forum, or vote on others’ ideas.

If you run into any problems when using the DevTest Labs or have any questions, we are ready at the MSDN forum to help you.

Read the whole story
6 days ago
Baltimore, MD
Share this story
1 public comment
9 days ago
This is huge for teams using Azure IaaS. The ability to auto-shutdown VMs is crucial to keeping costs down in the cloud-enabled world.
Seattle, WA

Please Don't Learn to Code from Stock Photos

1 Share
Read the whole story
6 days ago
Baltimore, MD
Share this story

ngMigrate Helps You Move from AngularJS 1.x to Angular 2

1 Share


Read the whole story
6 days ago
Baltimore, MD
Share this story
Next Page of Stories