Skip to content

ricardofabila/hapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

hapi

πŸš€ hapi

A batteries included CLI tool to hit our APIs

I Have Delivered Value... But At What Cost?

About β€’ Quickstart β€’ Installation β€’ Dependencies β€’ Features β€’ Configuration β€’ Credits β€’ TODOs

Version 1.0.0 Version 1.0.0


"All men dream, but not equally. Those who dream by night in the dusty recesses of their minds, wake in the day to find that it was vanity: but the dreamers of the day are dangerous men, for they may act on their dreams with open eyes, to make them possible."

T.E. Lawrence


πŸ“– About

This tool helps you use our backend APIs.

  • Adds the necessary authentication headers to the request per environment automatically.
  • Supports multiple environments (production, staging, etc).
  • And more, keep scrolling

⚑️ Quickstart (the TLDR)

This small section is meant to help you get started in no time. Just get an executable from the releases page like the installation section says. Or use fox, just add this repo to your local packages and run fox install hapi.

The file we care about is the config (located in ~/.hapi/config.yaml) which gets created automatically and populated with nice defaults.

We are going to need to set up a prod environment. Add the following under the enviroments section:

environments:
  prod:
    authorizationHeaderJWT: <your jwt>
    address: http://localhost/api/v1

To get the values for authorizationHeaderJWT, use your browser to go to the web app of the environment you want to set up, and locate a request ( eg: /api/v1/users/me), see the cookie header and copy them from there.

If you did everything correctly you can try the following commands:

> hapi config # this will print out your config file
> hapi doctor # this will check your environment for potential problems and possible enhancements

πŸ€– Installation:

This project uses goreleaser to generate executable for the major operative systems. Just go to the releases page and download yours and move it somewhere that your PATH knows to look for.

Or, if knowing your OS and architecture + downloading a file + running a mv command is just too much for you. You can always use 🦊 fox to install.

Just run:

> fox install hapi

Build from source

  goreleaser release --snapshot --rm-dist

Dependencies:

βš“ Required

This tool is as zero-dependencies as it can possibly get.

  • cURL to use the api command. Make sure you have curl installed and your path.

That's it. Seriously, you don't even need to install jq or gojq as this adds gojq as a library and lets you pass a --jq flag, so you don't even need to pipe it (the reason to use this, is so now your query gets saved to your history). And it also pretty-prints JSON responses automatically (but you can change that πŸ˜‰).

🍹 Optional

  • slit is a cool pager that supports colors
  • most is a cool pager that supports colors

πŸŽ‰ Features

hapi

Some many cool features to list them all. Be warned, once you use this tool

Multiplatform

Executables for the major operative systems.

Configurable

Granular control via --flags for one time changes and via a single global config.yaml file.

Want to hide the date when browsing your history? You can do it.

Want to automatically URL encode custom endpoints? Yes, there is even a configuration option for that. Go to the Configuration section for details.

Doctor

Use the built-in doctor command to check for problems as well as recommendations.

Autocompletion

Use the built-in completion command to generate auto-completions for various shells.

History

Have you ever tried to find that one command you ran last week, but pressing looking in your shell history proves to be cumbersome? I gotcha fam. hapi saves every query in a history file, and it even lets you search.

Easily my favourite feature and 99% of the reason I made this in the first place as I can never remember the shortcut to launch my shell's history, and I just can't be bother to looks it up. Enjoy!

Pipe to pager automatically (disabled by default)

Use your favorite pager program to browse and live search api responses. And yes, you can set it via a flag for one-time use and in the config file. This behaviour is disabled by default.

...and so many more


βš™οΈ Configuration

You have quite granular control over this tool. It uses a single config file located in ~/.hapi/config.yaml. This way you can set the defaults for most of the command --flags.

The yaml file get created automatically when you first run hapi with a default configuration. It contains several sections; one for each sub command.

Note: Make sure you use camelCase or alllowercase for the keys, otherwise they won't load correctly.

Example of a ~/.hapi/config.yaml file:

api:
  color: true
  env: prod
  pager: ""
  downloads: "/Users/your-username/Downloads"
environments:
  local:
    authorizationHeaderJWT: "<YOUR-THING>"
    address: "http://localhost/api/v1"
  stage:
    authorizationHeaderJWT: "<YOUR-THING>"
    address: "https://staging.example.com/api/v1"
  prod:
    authorizationHeaderJWT: "<YOUR-THING>"
    address: "https://jsonplaceholder.typicode.com"
history:
  enabled: true
  unique: true
  color: true
  date: true
  interactive: true
  max: 100
  saveUnsuccessful: false

Command sections

Sections Key Type Default What it does
history
enabled bool true Enable the history feature.
unique bool true When displaying your history records, remove duplicates. This is to make your list smaller, but can be useful to see duplicates in --interactive mode to check differences on how long did it took the same endpoint to respond (say you are implementing a cache).
color bool true When displaying your history to stdout (eg: non interactive mode) show nice colors.
date bool true Display the date when displaying your history records.
interactive bool true Automatically load your history in --interactive mode when you run hapi history.
saveUnsuccessful bool false Save commands that are invalid.
max int 100 How many history records to load by default (latest always load first) when displaying records.
api
color bool true When displaying JSON responses to stdout, show nice colors.
env string prod What environment to use by default if --env is not set.
downloads string "./" When using the --all flag, it saves the generated file to the directory specified here. You can set a relative or absolute path.
pager string "" Automatically pipes the output to the specified pager program (eg: "less") I STRONGLY suggest using 'slit' or 'most' as they support colors while 'less' and 'more' don't. Set to empty string if you want to turn it off.

Environments section

To save you a lot of time hapi will manage your tokens and refresh them automatically. Use the show subcommand for token (hapi token show) to help you with making sure your token is correct.

Section Key Type Default What it does
environments This sections is a map[string][EnvironmentConfig]
authorizationHeaderJWT string "" Your authorization token to be used as a Authorization Header when making requests on the environment.
address string "" The base host to use when making api calls (eg: "https://stage.example.co/api/v1").

πŸ’³ Credits

Made with ❀️ by @ricardofabila

About

The CLI for all your APIs πŸ¦„

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages