Git Product home page Git Product logo

wsget's Introduction

wsget

Tests codecov Go Report Card License: MIT

wsget is a command-line tool for interacting with a WebSocket server. It supports plain text and JSON messages and can save the output of the session into a file.

Installation

Downloading binaries:

Compiled executables can be downloaded from here.

Install from source code:

go install github.com/ksysoev/wsget/cmd/wsget@latest

Install with homebrew:

brew tap ksysoev/wsget
brew install wsget

Usage

To use wsget, you need to specify the WebSocket URL:

wsget wss://ws.postman-echo.com/raw

You also can pass the initial request as part command line argument by using flag -r

wsget wss://ws.postman-echo.com/raw -r "Hello world!"

By default, wsget will print the data received from the WebSocket server only to the console. You can also save the data to a file using the -o flag:

wsget wss://ws.postman-echo.com/raw  -o output.txt

Example:

wsget "wss://ws.derivws.com/websockets/v3?app_id=1" -r '{"time":1}'
Use Enter to input request and send it, Ctrl+C to exit
->
{
  "time": 1
}
<-
{
  "echo_req": {
    "time": 1
  },
  "msg_type": "time",
  "time": 1698555261
}

Macros

wsget provides a possibility for customization. You can create your sets of macros with a configuration file. the file should be located at ~/wsget/macro/your_configuration.yaml. wsget will read all files from this directory and use only configuration files that match the WebSocket connection hostname.

version: "1"
domains:
    - example.com
macro:
    ping:
        - |-
          send {
              "ping": 1,
          }
        - wait 5

Primitive commands

  • edit {"ping": 1} opens request editor with provided text
  • send {"ping": 1} sends requests to WebSocket connection
  • wait 5 waits for responses or provided time out, whatever comes first. If the timeout is reached then an error will be returned. if 0 is provided command will wait response without a time limit
  • exit interrupts the program execution
  • repeat 5 send {"ping": 1} repeat provided command or macro defined number of times
  • sleep 1 sleeps for the provided number of seconds

Macros arguments

Macro support Go template language. It provides a possibility to pass arguments to your macro command and substitute or adjust the behavior of your macro commands.

version: "1"
domains:
    - example.com
macro:
    authorize:
        - |-
          send {
              "authorize": "{{index .Args 0}}",
          }
        - wait 2

Macros presets

License

wsget is licensed under the MIT License. See the LICENSE file for more information.

wsget's People

Contributors

dependabot[bot] avatar ksysoev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

wsget's Issues

Terminal doesn't accept input

In request mode, if you enter an invalid request, program exits and you can't use the terminal anymore.

e.g.

./wsget -u 'wss://<server>'
Connection Mode: Press ESC to enter Request mode
Request Mode: Type your API request and press Ctrl+S to send it. Press ESC to cancel request
sfdsf   <ctrl+S>
Connection Mode: Press ESC to enter Request mode
sfdsf

2023/10/23 11:37:26 Fail to read from WS connection:EOF

Now you can't type anything.

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.