Giter Site home page Giter Site logo

pthorpe92 / cute Goto Github PK

View Code? Open in Web Editor NEW
166.0 4.0 3.0 5.4 MB

HTTP client/libcurl TUI front end in Rust, with request + key storage

License: GNU General Public License v3.0

Rust 100.00%
api-keys curl http ratatui rest-api-test rust tui postman-collection

cute's Introduction

TUI HTTP Client with API/Auth Key Management and Request History/Storage

This project is still in active development and although it is useable, there may still be bugs and significant changes are still needed to both refactor the codebase and add new features.

Collaboration is welcome and encouraged! There is lots of low hanging fruit ๐Ÿ‘ and cool ideas for additional features.

image

Curl TUI Environment (CuTE). HTTP client/libcurl front-end in Rust, using the awesome ratatui library designed to simplify the process of sending HTTP requests in the terminal, allowing you to store and manage your previous requests + API keys.

This is a tool for when your requests are not complex enough for something like Postman, but more complicated than you would want to use curl CLI, or if you just don't want to remember all those commands. You can make a few requests to your back-ends for testing, set up with your API key and save the requests to be executed again later.

New: We now support importing your Postman collections, so you can have easy access to your APIs without leaving the terminal. (note: https://schema.getpostman.com/json/collection/v2.1.0/ is currently the only supported collection schema)

Features

  • Interactive TUI Interface: Intuitive TUI interface that makes it fast and easy to construct and execute HTTP requests without leaving the terminal.

  • Intuitive VIM keybindings: Vim-like keybindings are defaulted. Support to change them will eventually make it into the config file. (h or b is used to go back a page, j and k move the cursor up and down. i for insert mode while in an input box, enter to submit the form and esc to exit insert mode)

  • API Key Management: Very simple sqlite based API key storage system. You can choose to save a Key from a request, or add/edit/delete/rename them.

  • Postman Collections: Import your postman collections to have easy access to your APIs without leaving the terminal.

  • Response Visualization: Pretty-print JSON responses in a human-readable format within the TUI, then you can choose to write the response to a file after inspecting it. You an also copy the curl CLI command needed to make the same request to your clipboard.

  • This application builds and runs on Linux, Windows and MacOS.

Why?

  • Have you even ran curl --help all ?

  • I made this because I needed it. As a back-end dev that is testing API's daily, Postman is great but I have enough electron apps running as it is, and I live in the terminal.

Installation

Prebuilt binaries for non smelly-nerds are available on the Releases page (currently just x86-linux)

Install with Cargo:

  • Prerequisites: Make sure you have Rust and Cargo installed on your system.
  1. cargo install CuTE-tui

  2. make sure that your ~/.cargo/bin directory is in your PATH

  3. cute or cute --dump-config . # this will put a config.toml file in your cwd. You can edit this and place it in a dir in the ~/.config/CuTE path (see below) to customize the colors and some behavior of the application.

Build from source:

  1. Prerequisites: Make sure you have Rust and Cargo installed on your system.

  2. Clone the Repository: Clone this repository to your local machine using the following command:

    git clone https://github.com/PThorpe92/CuTE.git && cd CuTE
    
  3. Build and Run: Build and run the application using Cargo:

    cargo build --release 
    
  4. Move Binary: Move the binary to a location in your PATH of your choosing:

    cp target/release/cute ~/.local/bin/
    

Command Line Options

cute [OPTIONAL] '--dump-config ' or '--db-path <'/PATH/to/cute.db'>'

  • --dump-config: Dumps the default config.toml file to the specified path. If no path is specified, it will output it to the current working directory.

    • This config.toml file needs to be placed in ~/.config/CuTE/{config.toml} in order for the application to read it.
    • currently the config file can only specify basic colors of the application, and the path to the sqlite database. More options will be added in the future.
  • --db-path: Specify the path to the sqlite database. If no path is specified, it will default to data_local_dir working directory.(~/.local/share/CuTE/CuTE.db or the windows/macos equivalent)

Menus

  1. Main Menu: The main menu will provide options to create different types of HTTP requests and manage API keys.

  2. Request Type: Select the type of HTTP request you would like to make. The tool supports GET, POST, PUT, PATCH, HEAD, DELETE and custom requests.

  3. API Key Management: In the API key management section, you can add, edit, or delete API keys. Assign API keys to profiles and specific requests for easy integration.

  4. Viewing Responses: After executing a request, the tool will display the response in a readable format within the TUI, with the option to write it out to a file.

  5. Saved Commands: Much like the API keys, you can store and view past requests/commands for easy use later on.

Contributing

Contributions to this project are welcome and encouraged! If you encounter any bugs, have suggestions for improvements, or want to add a new feature, feel free to open an issue or submit a PR.

Before contributing, please review the Contribution Guidelines.

License

This project is licensed under the GPL3.0 License.


If you have any questions or need assistance, feel free to reach out

Fun fact:

This project was developed in the Maine State Prison system, where the author is currently incarcerated. I would like to bring whatever awareness possible to the importance of education and rehabilitation for those 2.2 million Americans currently incarcerated. I have a blog post if you are interested in reading about my story.

Disclaimer: This project is provided as-is, and its creators are not responsible for any misuse or potential security vulnerabilities resulting from the usage of API keys.

cute's People

Contributors

gierens avatar iteroji avatar kmastroluca avatar pthorpe92 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

cute's Issues

Print response to stdout no matter what user selects

I have found that in regular use, that copying response to clipboard SUCKS on X11 (TODO: Try to find fix for X11 clipboard issue) so unless u write to a file, the response is practically gone when you close the program.

The response should be written to stdout (pretty-printed). Although this does suck when you get the wrong response, and it's 200 lines of garbled html or xml.. so I guess that is why currently you are shown the response and given the choice of writing it out to a file.

But I guess in curl you would get that anyway, so probably in all cases, except when written to a file, the response should be printed to stdout.
Maybe if the file was written, we pipe the file to cat on unix systems. (bat if it exists on the system, if not fall back to cat)

[Test] - API Testing

Should we (me) maybe whip up a node js api so we can test more complicated kinds of requests where we know beforehand whats supposed to be returned by every end point and in what format and so on?

curl command -> json

So i have implemented saving command strings in the database, about to submit a PR for this.

What i now realize is that we cannot just execute the command string like we do with wget because it will be a cross-platform nightmare.

So a feature that takes a curl command struct, and turns it into a JSON file that we can serialize and store in the sqlite db along with the command string, and then we can offer users a way to execute the command again instead of just get the string.

So we need a json parser that can get the saved struct and execute all the commands on a curl::Easy::new() to get it to the state that the saved command was in, before we call execute()

This will be cool. probably fun to write. so i'll do it ๐Ÿ‘

Expand to testing gRPC

As most of this applications use comes with testing API's/back-ends, I'd like to build a menu where a user can dynamically compile .proto files, and get a client and a UI to then test their gRPC servers. Longer term goal

actually release v0.0.1

I wasn't planning on this even being open source yet at this point. But i'm glad I did because it has forced me to work on stuff I probably would have put off. These are things I would like to see fixed prior to an actual 0.1.0 release

  1. Comprehensive testing of authentication methods (libcurl has feature flags for SPNegotiate, NTLM.. and when I enabled them for a test, the ci fails on dependencies. I would then have to assume, that those probably dont work. although there are some questions)
  2. Better response display.. perhaps we just have an option to pipe the output to cat (bat) ?
  3. Find out how to fix damn clipboard on xorg clears itself when the program ends.. essentially making "copy to clipboard" worthless. I know it works on mac, speaking of which.
  4. Setup cross comp/build on mac

Errors persist when backing up screens

If I go from screen A to screen B, and enter some invalid information (such as an invalid path to an SSL certificate), when I go back to screen A (the request screen) there will be an appropriate error message on the top of the screen letting me know I have entered an invalid path.
If I then navigate to another page (such as the "More Options" page) and then navigate back to screen A.. I will be presented with the same error on the top of the screen letting me know I entered an invalid path, even though that path was never actually input, so I need not be reminded about that again.

Argument parsing (clap!)

on top of offering a config file at ~/.config/CuTE/config.toml where someone can specify the colors of the app, (eventually the keybindings), and the path to the database, I would also like to be able to run
CuTE --db-path ~/local/share/cute.db

and specify a custom path, giving the option for someone to just use a shell alias for cute or whatever, if they dont want to make a config file.

Clap is obviously the answer here

cli command won't save to clipboard on X11

Tried about every x-platform clipboard crate out there. Had friends test it on windows and macOS and everything seems fine, but I'm still unable to copy command to the clipboard on DWM/X11

[UI] - Lets Create A Couple Different Kinds Of Screens We Will Reuse Over And Over.

Im thinking the following:

  • 1 Line Text Input (URLs, Raw Body Input, Etc)
  • Multi-line Text Input (Not Sure What The Use Case Might Be Yet) ?
  • Key/Value Input, 2 Text Boxes Side By Side, i to begin input on the key, enter brings you to value input, enter again confirms the input, Escape brings you to the previous input and eventually backs out of the screen.
  • Data Add/Remove/Edit
    I see this one as kind of a list and you can hit a to add a new item, r to remove an item, and e to edit an existing item which would take you into one of the input/edit screens.

Auth key not working when deserialized and ran from DB

I'm getting a "invalid access token" error when running a command that I know worked when I saved it. Must be an error in easy_from_opts() or somewhere in

impl<'a> Serialize for Curl <'a> {
let mut map_struct: Map<Visitor> = HashMap::new();
// blah blah blah

Can't Open SQLite File On Windows

Whatever the same issue that was being caused by App tests on our build before, is now happening locally on my machine after I pulled your latest code.

Im getting an error related to the inability to open the SQLite3 file. When I check the directory that its in on Windows C:\Users\username\AppData\Local\CuTE\CuTE.db CuTE.db is showing up as a directory not a SQLite database file.


thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file: C:\\Users\\k.mastroluca-clark\\AppData\\Local\\CuTE\\CuTE.db"))', src\app.rs:72:36

This is happening on startup before anything happens, its blocking my ability to open the app at all.

Idioms + error handling

There is still quite a bit of messy code and poor practice surrounding things like error handling, mostly because this was my first decent sized rust project. Although I have already done a couple significant refactors, there is still quite a bit left to do. Some files were split up too small, and others are absurdly large. There are a few patterns that I really can't stand now that only one back-end (curl) is being used, where as before when wget was there, it made more sense to have global application options be set separate from the request options themselves. Now that it doesn't have to abstract that and be generic over two clients, there's a lot of duplication that could be removed.

[GET REQUEST] - Adding Request Body

Most likely this is in JSON format. So we should think about possibly emulating the functionality of header input where we create a screen that allows adding and removing key/value pairs. The only thing is we should allow for raw text input as an option and if we do key/value pairs, we might have to figure out a way for a value to be another set of key/value pairs, which might get....complicated.

More Tests

Postman collection importation needs testing around it, as well as input validation for a few of the new features. Most of the existing tests were written very early.

Expand vim keybindings for more than just naviation

When entering input (although this is currently single-line/cursor), the ability to move around when not in insert mode would be pretty cool, considering the rest of the application uses vim keys by default.

Testing Authentication types

Currently I have only been able to test Bearer auth..

Obviously testing this would more or less be testing the libcurl bindings, which I'm quite confident in. But nonetheless there is always the chance that something isn't setup properly, so a way needs to be figured out to test the remaining authentication methods.

Menu options

I think offering HTTP requests with any of those 3 options (HTTP custom, cURL, or wget) is just pointless, as I cannot see any reason why someone would want to send a GET or POST request with wget as opposed to cURL.

I think I am going to strip all the functionality of WGET aside from recursive downloads (the only thing it can do that curl cannot.)
AND
remove the option for custom HTTP requests (using reqwest) unless someone can provide me with a good reason not to. Because i just cannot think of any. Whether you use libcurl or some custom client.. it's all the same. and curl allows you to save the command and share it to run on servers or anything else you might want to do with it.

[Windows] Lets Make It Clear What The Buttons Do.

Feature

I almost put in an issue about a bug where text entry didn't work at all on Windows until i realized its mapped to [i] for input a-la Vim. I know that's totally a common thing. Let's put a legend somewhere on the screen so users know what they are supposed to do.

Additionally, maybe lets think about, in the future, adding a setting that allows for a "dummy" ui control setup where the user can select the control they wish to interact with using the arrow keys, and/or mnemonic keystrokes (aka Alt+u to direct input to the URL text box.) Then choose to direct input, or interact with the control using enter, and backing out to control select mode (or the previous menu) with escape.

implement lifetimes, remove tons of unnecessary heap allocated strings

Lots of naive, useless heap allocations left over. As my first decent sized Rust project, there was quite a bit of learning going on. But now, going back and adding lifetimes and borrowing properly and not doing stupid clones everywhere, is necessary ๐Ÿ‘

Starting to work on this, and the error poor error handling.

Better Error handling

This project is full of horrendous practices due to still being in pre-0.1 release stage, many of those are examples of poor error handling, such as flagrant use of .unwrap() (although there are quite a few that are justified, like app.command.as_ref().unwrap().some_method() where there will always be a command field when those methods are called.

However, there is still much to do in terms of error handling. This is simple stuff and I really wish this was hacktoberfest still so people could get some easy PR's merged (on a rust project no less :D )

The name...

I think this will need a far more clever name before it gets released. Chat gippity has offered some pretty horrible suggestions. These are a few that came to mind

RUSTfull    (lawsuit?)

fetchMate

tuiFetch

Post-it

Ehko

Qwest

What are we doing here in Curl.rs

im confused by this.

            transfer

                .write_function(|new_data| {
                    let mut data = data.borrow_mut();
                    data.extend_from_slice(new_data);
                    Ok(new_data.len())
                })
                .unwrap();

Why are we unwrapping here, when the value isnt being assigned to anything?
im currently debugging an issue I ran into related to trying to submit nonsense requests. We crashed because later in this function call we try to unwrap an error when we were expecting a value. I fixed that

            match transfer.perform() {
                Ok(_) => {
                    let res = String::from_utf8(data.take()).unwrap();
                    self.resp = Some(res.clone());
                    Ok(())

                }
                Err(e) => {
                    let res = format!("Error Executing Curl Request: {}", e);
                    self.resp = Some(res.clone());
                    Err(e)
                }
            }

Now we match on the transfer.perform() and anything that results from it, success or error, will get thrown into self.resp so we can display the result to the user.

This does avoid the panic I encountered with a nonsense request
but im not seeing the error / response displayed, just a blank screen, so im pretty confused. Im looking into it further and I encountered that .unwrap() without an assignment. Whats that for?

Add more Request metadata

To make postman collections more useful than simply importing groups of requests, I'd like to have more relevant data stored about the requests. I'm unsure as to whether or not responses should be stored, as I think that's a bit out of scope for the project.
Unsure if there are enough (any) users where database migration would be needed, likely could just be a breaking change.

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.