Giter Site home page Giter Site logo

knid / httpy Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 2.0 3.51 MB

Modern, user-friendly, programmable command-line HTTP client for the API.

License: MIT License

Python 100.00%
python3 python http http-client cli httpcli api-client client httptools requests

httpy's Introduction

HTTPie
Modern, user-friendly, programmable and filterable command-line HTTP client for the API

HTTPy is a command line HTTP client. Its purpose is to make duplicate web requests on a single line. httpy is designed for testing, debugging, and generally interacting with APIs and HTTP servers. The httpy command allows creating and sending arbitrary HTTP requests. They use simple and natural syntax and provide formatted and colored output. Under favour of its programmable structure, it can perform many tasks at the same time. For example, you can pull data for user IDs 0, 1, and 2 at the same time

httpy in action

Features

  • Expressive and intuitive syntax

  • Formatted and colorized terminal output

  • Programmable requests

    • Multiple requests one line

    • Value increment each time

    • Random number per request

    • Read each value from the lines in the file

    • Value per each request as a list of multiple values

  • Built-in JSON support

  • Arbitrary request data

  • Custom headers

Installation

$ pip3 install httpy-cli

Usage

Simple get request:

httpy httpbin.org/get

Synopsis:

$ httpy <URL> <METHOD> <HEADERS,QUERIES,DATA> --exec <COMMAND> <ARGS>

We will use api.service.com as a API server for simulating requests.

Let's start with a simple request:

$ httpy api.service.com/users

This command will return all user objects. But if we want get only users with id 0, 1, 2, 3. Normally we have to do like this:

$ httpy api.service.com/users/0
  ...
$ httpy api.service.com/users/1
  ...
$ httpy api.service.com/users/2
  ...
$ httpy api.service.com/users/3
  ...

But we can do this in one line with httpy:

$ httpy 'api.service.com/users/{i}' -X i:0,1,2

This will be return all response for these ids.

i is arg name and it can be everything. And -X argument execute commands.

Variable name must be same with inside of {}. We can use {i} in everything. Headers, query values etc.

We can more simply the command:

$ httpy 'api.service.com/users/{i}' -X i:++:4

This command increment the variable each time.

The command syntax must be like this:

<VALUE>:<OPERATION>:<MAX_RUN>

We can use different operation:

Operation Description
++ Increment
-- Decrement
rand(0,10) Random number from 1 to 10
read(path/to/file) Read lines from file
item1,item2 List
item Text

For exaple we can get random number and use in request:

$ httpy 'api.service.com/users/{i}' -X 'i:rand(1,10)'

or we can use file as a token list for deleting users:

$ httpy 'api.service.com/users/me' DELETE 'Authorization:{i}' -X 'i:read(tokens.txt)'

or we can fill db with random 100 data in one line (we will see only status with -S):

$ httpy 'api.service.com/books' POST 'id={i}' 'title=Book {i}' -X 'i:rand(1,3000):100' -S

We can get only body with -B argument.

$ httpy 'api.service.com/users/{i}' -X i:3,4,5 -B

We can use other arguments for choosing what will see:

Argument Description
-B, --body Only show body
-H, --header Only show headers
-S, --status Only show status

We can combine args. For example we can print only body and status with -B and -S:

$ httpy 'api.service.com/users/{i}' -X i:3,4,5 -B -S

That's it. You can check project page for all "operations" and all usages.

Community & support

Contributing

Have a look through existing Issues and Pull Requests that you could help with. If you'd like to request a feature or report a bug, please create a GitHub Issue using one of the templates provided.

Sinan Kanidağlı © 2022

httpy's People

Contributors

deepsource-autofix[bot] avatar deepsourcebot avatar dependabot[bot] avatar knid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.