Giter Site home page Giter Site logo

hopp-cli's Introduction

⚠️⚠️⚠️⚠️⚠️⚠️

This project is now archived. If you want to use Hoppscotch as a CLI client for CI/CD purposes, please use the new Hoppscotch CLI.

⚠️⚠️⚠️⚠️⚠️⚠️

Hoppscotch CLI hoppscotch Go Report Card

Send HTTP requests from terminal and Generate API Docs. An alternative to cURL, httpie ⚡️

Installation

From Script

$ sh -c "$(curl -sL https://git.io/getpwcli)"

From Source

  • Clone the repo
$ git clone https://github.com/hoppscotch/hopp-cli.git
  • Build and install
$ make
$ sudo make install

From Binary

  • You can download prebuilt binaries from the Releases page.
  • Supported platforms:
    • Linux (x64, x86)
    • Mac (x64)
    • Windows (x64, x86)

IMPORTANT: Not tested on Windows, please leave your feedback/bugs in the Issues section

Arch GNU/Linux

  • You can install from AUR
  • There are three different packages available
Name Link Description
hopp-cli-bin https://aur.archlinux.org/packages/hopp-cli-bin/ Pre-built binary
hopp-cli https://aur.archlinux.org/packages/hopp-cli/ Compiled from latest release
hopp-cli-git https://aur.archlinux.org/packages/hopp-cli-git/ Compiled from latest commit

Homebrew

Install by

brew install athul/tap/hopp-cli

Windows

You can download pre-built binaries from the Releases page.

Alternatively, you can install hopp-cli via Scoop:

scoop install hopp-cli

Usages

Putting Simply: Just pass the URL to the request method

Basic Commands

  • GET : $ hopp-cli get <url>
  • POST: $ hopp-cli post <url>
  • PATCH: $ hopp-cli patch <url>
  • PUT : $ hopp-cli put <url>
  • DELETE: $ hopp-cli delete <url>

Example for a POST request:

$ hopp-cli post https://reqres.in/api/users/2 -c js -b '{"name": "morp","job": "zion resident"}'

Extra Commands

  • send for testing multiple endpoints
  • gen for generating API docs from Collection

SEND

This can be used to test multiple endpoints from the hoppscotch-collection.json file.

The output will only be the statuscode

Example:

$ hopp-cli send <PATH to hoppscotch-collection.json>

Sample output:

send-output

GEN

The gen command generates the API documentation from hoppscotch-collection.json file and serves it as a static page on port 1341.

Example:

$ hopp-cli gen <PATH to hoppscotch-collection.json>

Sample Hosted site: https://hopp-docsify.surge.sh/

Powered by Doscify

Flags:

  • browser or b to toggle whether the browser should open automatically [Boolean]
  • port or p for specifying the port where the server should listen to [Integer]

There are 3 Authentication Flags

(optional)

  • -t or --token for a Bearer Token for Authentication
  • -u for the Username in Basic Auth
  • -p for the password in Basic Auth

There are 2 flags especially for the data management requests like POST, PUT, PATCH and DELETE

  • -c or --ctype for the Content Type
  • -b or --body for the Data Body, this can be of json, html or plain text based on the request.

Enclose the body in Single Quotes(')

Content Types can be of

Short Code Content Type
js application/json
html text/html
xml application/xml
plain text/plain

Include Arbitrary Headers

  • -H or --header may be specified multiple times to include headers with the request.

Example:

$ hopp-cli get -H 'X-Api-Key: foobar' -H 'X-Api-Secret: super_secret' https://example.com/api/v1/accounts

Providing a Request Body via stdin

In addition to -b/--body, you may provide a request body via stdin.
If you combine this method with the -b flag, the body provided with -b will be ignored.

Example with Pipes

$ echo '{"foo":"bar"}' | hopp-cli post -c js http://example.com

Example with Redirection

$ cat myrequest.json
{
  "foo": "bar"
}

$ hopp-cli post -c js http://example.com <myrequest.json

Providing a Request Body via text-editor

In addition to providing request body via -b / --body flag and stdin, you can also use -e / --editor flag which opens default text-editor in your system.

Example:

$ hopp-cli post https://reqres.in/api/users/2 -c js -e

It will preferrably open editor based on $EDITOR environment variable.

For example: If the environment variable is $EDITOR=code it will open VSCode for request-body input. Else, it will use default editor value based on the OS.

OS Default Editor
Linux nano
macOS nano
Windows notepad

hopp-cli's People

Contributors

aliesbelik avatar andrewbastin avatar arshchimni avatar athul avatar avelino avatar bro3886 avatar dependabot[bot] avatar devblin avatar gbmor avatar liyasthomas avatar shtakai avatar ssiyad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

hopp-cli's Issues

Installation script seems bugged

Hello,

I tried to install through the script on Windows 10 (with WSL2) and then on a Linux VM (Ubuntu 20.04.3 LTS) without success. It prints the version and does nothing else :

julien@julien-VirtualBox:~$ sudo sh -c "$(curl -sL https://git.io/getpwcli)"
[sudo] Mot de passe de julien : 
athul/pwcli info checking GitHub for latest tag
athul/pwcli info found version: 0.0.8 for v0.0.8/Linux/x86_64
julien@julien-VirtualBox:~$ hopp-cli --help
hopp-cli : commande introuvable
julien@julien-VirtualBox:~$ 

I think the script is bugged.
Installation worked fine through downloading the release manually.

By the way what is pwcli ?

`headers` schema change

The headers schema seems to be different between hoppscotch.io and the hopp-cli. The CLI is expecting an array of strings, but hoppscotch.io produces an array of key/value objects. An example of an exported collection is below.

[
  {
    "name": "My Collection",
    "folders": [],
    "requests": [
      {
        "url": "https://httpbin.org",
        "path": "/get",
        "method": "GET",
        "auth": "None",
        "httpUser": "",
        "httpPassword": "",
        "passwordFieldType": "password",
        "bearerToken": "",
        "headers": [
          {
            "key": "My-Header",
            "value": "hello"
          }
        ],
        "params": [],
        "bodyParams": [],
        "rawParams": "",
        "rawInput": true,
        "contentType": "",
        "requestType": "",
        "preRequestScript": "// pw.env.set('variable', 'value');",
        "testScript": "// pw.expect('variable').toBe('value');",
        "label": "Test",
        "name": "Test",
        "collection": 0
      }
    ]
  }
]

pwcli to hscli?

Since it was changed from PostWoman to Hoppscotch will change the name of this project?

error parsing JSON: json: cannot unmarshal object into Go value of type []methods.Collection

running hopp-cli v0.0.8 (and v0.0.7) both in windows 10 and linux (ubuntu 22 via wsl) throws error parsing JSON: json: cannot unmarshal object into Go value of type []methods.Collection

my command .\hopp-cli.exe send .\base.json

base.json
{"v":1,"name":"base","folders":[],"requests":[{"v":"1","endpoint":"http://localhost:3010/todo","name":"a","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true,"addTo":"Headers","key":"","value":""},"preRequestScript":"","testScript":"","body":{"contentType":null,"body":null}}]}

Validating URL

The URLs for requests are not validated and could sometimes lead to errors.

This can be easily fixed with net/url package

Brew Installation Failure

When trying to install via Brew it fails with the following:

% brew install athul/tap/hopp-cli
==> Tapping athul/tap
Cloning into '/usr/local/Homebrew/Library/Taps/athul/homebrew-tap'...
remote: Enumerating objects: 98, done.
remote: Counting objects: 100% (98/98), done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 98 (delta 20), reused 18 (delta 2), pack-reused 0
Receiving objects: 100% (98/98), 13.68 KiB | 1.05 MiB/s, done.
Resolving deltas: 100% (20/20), done.
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb
shelby: /usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb:17: syntax error, unexpected end
      end
      ^~~
/usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb:25: syntax error, unexpected end
      end
      ^~~
/usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb:36: syntax error, unexpected end
      end
      ^~~
/usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb:44: syntax error, unexpected end
      end
      ^~~
/usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/shelby.rb:52: syntax error, unexpected end
      end
      ^~~
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/pwcli.rb
pwcli: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the athul/tap tap (not Homebrew/brew or Homebrew/core):
  /usr/local/Homebrew/Library/Taps/athul/homebrew-tap/Formula/pwcli.rb:6

Error: Cannot tap athul/tap: invalid syntax in tap!

Script doesn't work on Arch.

It doesn't error either but the binary is nowhere to be found.

It would be great to submit a package to AUR.

I fixed it by downloading and moving the binary directly.

Typo in readme

The readme says the command is pwcli when the command is actualy hopp-cli

FEAT: Add support for inserting request body through external editor

Currently, for making request with request body with have to add the data in inline mode like this: '{"name": "morp","job": "zion resident"}' this is good for small data, but for more request data user may want better way.
For above mentioned problem, we add support for using external editor with default file (to take input for request data).
So, basically if the user wants to add data through editor, they can use a flag.

Update Goreleaser

Hopp-cli uses goreleaser version and yml from 2019 🙈 . We want to update the goreleaser.yml file for better releasing and packaging. If anyone is willing to take this up, would be great.

For further questions you can ping me, making this an issue due to a backlog of changes

Better Error Logs

The Errors logs just shows Go's usual Panic Output. Maybe we could wrap an abstraction for that. Like
Request Error or Check the URL/URI and Authentication

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.