← Back to eliangcs/http-prompt

How to Deploy & Use eliangcs/http-prompt

# HTTP Prompt Deployment & Usage Guide

An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and persistent context.

## Prerequisites

- **Python**: Version 3.6 or higher (required for modern typing and string handling)
- **pip**: Python package manager (or `pipenv`/`poetry`)
- **Terminal**: ANSI-compatible terminal with readline support (required for `prompt_toolkit` functionality)
- **HTTPie**: Installed automatically as a dependency, but verify no conflicting versions exist

## Installation

### From PyPI (Recommended)

```bash
pip install http-prompt

Verify installation:

http-prompt --version

From Source

git clone https://github.com/httpie/http-prompt.git
cd http-prompt
pip install -e .

System Dependencies

Ensure your system has the required build tools for Python C extensions (used by dependencies like parsimonious):

Ubuntu/Debian:

sudo apt-get install python3-dev build-essential

macOS:

xcode-select --install

Configuration

HTTP Prompt follows the XDG Base Directory Specification for configuration and data storage.

Configuration Files

  • Config Directory: $XDG_CONFIG_HOME/http-prompt/ or ~/.config/http-prompt/
  • Data Directory: $XDG_DATA_HOME/http-prompt/ or ~/.local/share/http-prompt/
  • Config File: config.yml (YAML format)
  • History File: history (stored in Data Directory via FileHistory)

Key Configuration Options

Create ~/.config/http-prompt/config.yml:

# Cookie handling: 'auto', 'ask', or 'never'
set_cookies: auto

# Default HTTPie options applied to all requests
default_options:
  - --follow
  - --timeout=30

Environment Variables

  • XDG_CONFIG_HOME: Override config directory location
  • XDG_DATA_HOME: Override data directory location
  • HTTP_PROMPT_CONTEXT: Path to default context file to load on startup

Build & Run

Development Setup

  1. Clone and setup virtual environment:
git clone https://github.com/httpie/http-prompt.git
cd http-prompt
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install in editable mode with dev dependencies:
pip install -e .
pip install pytest flake8  # for development
  1. Run locally:
http-prompt http://httpbin.org

Basic Usage Workflow

Start with a base URL:

http-prompt https://api.example.com

Interactive commands:

# Navigate URL paths (cd)
cd /v1/users

# Set headers and parameters (mutations)
Authorization:Bearer token123
page=1
limit=20

# Preview the HTTPie command without executing
httpie

# Execute request
get

# Preview as curl
curl post /users name=john

# Save response to file
get > output.json

# Pipe to shell commands
get | jq '.data'

# Manage context
ls          # List current context
env         # Show environment variables
rm -h Authorization  # Remove header
clear       # Clear screen

# Execute commands from file
source script.http
exec script.http  # Execute without changing context

# Exit
exit

Grammar Features

The parser supports:

  • Concatenated mutations: param=value header:value option==value
  • Quoted values: name="value with spaces", name='single quoted'
  • Output redirection: > file (overwrite), >> file (append)
  • Piping: | jq '.', | grep pattern

Deployment

As a CLI tool, deployment focuses on distribution and packaging rather than server deployment.

PyPI Distribution

Build and upload:

python setup.py sdist bdist_wheel
twine upload dist/*

Docker Deployment

Create a Dockerfile for consistent environments:

FROM python:3.9-slim
RUN pip install http-prompt
ENTRYPOINT ["http-prompt"]

Build and run:

docker build -t http-prompt .
docker run -it http-prompt https://api.example.com

System Package Managers

Homebrew (macOS): Create a formula referencing the PyPI release:

class HttpPrompt < Formula
  desc "Interactive HTTP client"
  homepage "https://github.com/httpie/http-prompt"
  url "https://files.pythonhosted.org/..."
  sha256 "..."
  depends_on "python@3.9"
  
  def install
    virtualenv_install_with_resources
  end
end

Linux Packages: Build RPM/DEB packages using fpm:

fpm -s python -t deb http-prompt
fpm -s python -t rpm http-prompt

Troubleshooting

Terminal Compatibility Issues

Problem: Autocomplete or syntax highlighting not working Solution: Ensure $TERM is set correctly:

export TERM=xterm-256color

Import Errors / Module Not Found

Problem: ModuleNotFoundError: No module named 'httpie' Solution: Reinstall with dependencies:

pip install --force-reinstall http-prompt httpie

Permission Denied on XDG Directories

Problem: Cannot save history or context Solution: Fix permissions:

chmod 700 ~/.config/http-prompt
chmod 700 ~/.local/share/http-prompt

Grammar Parsing Errors

Problem: Commands fail with ParseError or VisitationError Solution:

  • Check for unclosed quotes in mutations
  • Escape special characters: name=value\ with\ spaces
  • Use quoted strings for complex values: name="value:with:colons"

Cookie Handling Issues

Problem: Cookies not persisting between sessions Solution: Verify config:

cat ~/.config/http-prompt/config.yml
# Ensure set_cookies is not set to 'never'

Slow Startup

Problem: Delay when starting HTTP Prompt Solution:

  • Check for large history files: ~/.local/share/http-prompt/history
  • Truncate if necessary: > ~/.local/share/http-prompt/history
  • Disable auto-suggestions if history is massive
# In cli.py, modify AutoSuggestFromHistory usage

HTTPie Plugin Conflicts

Problem: Formatter plugins causing output issues Solution: Run with --ignore-plugins or check httpie configuration in ~/.httpie/

http-prompt --ignore-plugins https://api.example.com