oriolrius.cat

Des del 2000 compartiendo sobre…

Tag: curl

HTTPie: The Next-Level Tool for Querying HTTP Resources

Reading time: 3 – 4 minutes

HTTPie is not only an intuitively designed tool, but it also offers user-friendly methods to send HTTP requests directly from the command line. For developers looking for a more elegant and visual approach than traditional tools like curl or wget, HTTPie comes as a refreshing solution.

Installing HTTPie Without System Packages

Sometimes, relying on system packages isn’t an option due to various constraints or the desire to always fetch the latest version directly. Here are three alternative methods to get the latest version of HTTPie:

Using curl with jq

curl -L -o http $(curl -s https://api.github.com/repos/httpie/cli/releases/latest | jq -r ".assets[] | select(.name == \"http\") | .browser_download_url")

Using wget with jq

wget -O http $(wget -q -O - https://api.github.com/repos/httpie/cli/releases/latest | jq -r ".assets[] | select(.name == \"http\") | .browser_download_url")

Python One-liner (Python 3)

python3 -c "from urllib.request import urlopen; from json import loads; open('http', 'wb').write(urlopen([asset['browser_download_url'] for asset in loads(urlopen('https://api.github.com/repos/httpie/cli/releases/latest').read().decode())['assets'] if asset['name'] == 'http'][0]).read())"

These methods ensure you’re directly fetching the binary from the latest GitHub release, bypassing any potential system package cache limitations.

Exploring HTTPie’s Features with Examples

To truly appreciate the capabilities of HTTPie, one should explore its rich array of features. The official HTTPie Examples page showcases a variety of use cases. From simple GET requests to more complex POST requests with data, headers, and authentication, the examples provided make it evident why HTTPie stands out.

For instance, performing a simple GET request is as easy as:

http https://httpie.io

Or, if you want to post data:

http POST httpie.io/post Hello=World

Dive deeper into the examples to discover how HTTPie can simplify your HTTP querying experience.

Conclusion

HTTPie offers a refreshing approach to HTTP interactions, bringing clarity and simplicity to the command line. With flexible installation methods and an array of powerful features, it’s an indispensable tool for developers aiming for efficiency. Give HTTPie a try, and it might just become your go-to for all HTTP-related tasks!

HTTPie – command line HTTP client

Reading time: 1 – 2 minutes

I imagine you are used to using curl for many command line scripts, tests, and much more things. I did the same but some weeks ago I discovered HTTPie which is the best substitute that I’ve ever found for curl. Of course, it’s also available for a lot of Linux distributions, Windows, and Mac. But I used it with docker which is much more transparent for the operative system and easy to update. To be more precise I use next alias trick for using this tool:

alias http='sudo docker run -it --rm --net=host clue/httpie'

Official website: httpie.org

Let me paste some highlights about HTTPie:

  • Sensible defaults
  • Expressive and intuitive command syntax
  • Colorized and formatted terminal output
  • Built-in JSON support
  • Persistent sessions
  • Forms and file uploads
  • HTTPS, proxies, and authentication support
  • Support for arbitrary request data and headers
  • Wget-like downloads
  • Extensions
  • Linux, macOS, and Windows support

From the tool webpage a nice comparison about how HTTPie looks like versus curl.

PHP: notes sobre arrays i tres classes (myCurl, barcodes, WSSoapClient)

Reading time: 2 – 3 minutes

A HowtoForge han publicat un howto (local) sobre com funcionen els arrays en PHP que esta molt bé. Realment el que més valoro són les notes sobre les funcions que menys s’acostumen a usar i per tant, les menys documentades o més mal documentades. Tot i que sovint quan les descobreixes ja no pots viure sense elles, funcions de búsqueda, de push, pop, var_dump per depurar, etc.

A més a través de phpClasses he trobat tres classes que els hi he de donar un bon cop d’ull ja que tenen molt bona pinta:

  • MyCurl This class provides an alternative implementation of the cURL extension functions in pure PHP. It automatically detects whether the cURL library is available. If it is not available, it defines several functions with the same names of the cURL extension that use the class to emulate part the original functionality. Currently it implements the functions: curl_init, curl_exec, curl_setopt and curl_close. Several of the most important options can be set with the curl_setopt function.
  • HTML Bar Codes This package can be used to display bar codes using only HTML with CSS styles. It takes a code to represent and generates CSS style definitions and HTML tags to render that code in an HTML page. There are two classes that can render bar codes using the Code39 and Interleave 2 of 5 standards respectively.
  • WSSoapClient This class can add WSSecurity authentication support to SOAP clients implemented with the PHP 5 SOAP extension. It extends the PHP 5 SOAP client support to add the necessary XML tags to the SOAP client requests in order to authenticate on behalf of a given user with a given password. This class was tested with Axis and WSS4J servers.