Skip to content

Import a curl command into a .http file #48

Closed

Description

@dataGriff

Why

Every API's docs have a curl example, and every bug report has one. apic curl goes one way; the reverse (paste a curl, get a named request) is what Postman, Insomnia and Bruno all offer, and it is the quickest way to grow a project from zero.

What

apic import --curl 'curl -X POST https://api.example.com/todos -H "Content-Type: application/json" -d "{\"title\":\"x\"}"' --into todos.http --name create-todo
pbpaste | apic import --curl - --into todos.http

Acceptance criteria:

  • Parses the common curl surface: -X/--request, -H/--header, -d/--data/--data-raw/--data-binary/--data-urlencode, -F/--form, -u/--user, --url, -G/--get, -b/--cookie, -A/--user-agent, -e/--referer, -k/--insecure, -L/--location, --compressed, @file bodies. Line continuations and both quote styles. Unknown flags are reported, not fatal.
  • Writes a ### block with # @name (from --name, else derived from method and path), # @assert status == 200, and < ./file for @file bodies. -u becomes # @auth basic, -k a comment noting --insecure.
  • Appends to --into (creating it if needed) or prints to stdout without --into. Rewrites the URL host as {{baseUrl}} when it matches the environment's baseUrl.
  • --json returns {"file", "name", "warnings": [...]}.

Where

New internal/curlimport/ (tokeniser with shell quoting rules and a flag table), internal/cli/import.go.

Docs

docs/cli.md (import section), docs/cheatsheet.md, docs/cookbook.md ("Start from a curl command").

Tests

Table of curl lines to expected .http output, including tricky quoting, --data-urlencode, multi-line with backslashes, and unknown flags producing warnings.

Activity

  1. dataGriff commented on Sep 20, 2026

    @dataGriff
    OwnerAuthor

    Shipped in #103: apic import --curl '<command>' [--into file.http] [--name n], with --curl - reading stdin. The listed flags are all read (plus --json and --oauth2-bearer), both quote styles, $'…' escapes and line continuations; unknown flags and curl's own output/transport options are notes, not errors; -u becomes # @auth basic, -k a comment, -F a multipart body, @file a < ./file; the host becomes {{baseUrl}} when the environment has one; a body the parser would misread goes into a side file with --into. --json prints {"file", "name", "request", "warnings"}. Docs: cli (import), cookbook (Start from a curl command).


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions