httpYac for Visual Studio Code

repository·main·Indexed 43 days ago

https://github.com/anweber/vscode-httpyac

A VS Code extension to send REST, SOAP, GraphQL, gRPC, MQTT, RabbitMQ, and WebSocket requests using a simple file-based syntax. Version 6.16.7 features include environment management, variable injection using {{name}} syntax, an integrated test runner, and customizable response viewing modes.

Tokens
8.4K
Snippets
16
Records
26
Agent score
56%

What's inside httpYac

  1. Use httpYac to send REST, SOAP, GraphQL, or gRPC requests

    main

    httpYac allows you to send various types of requests directly from your editor using a specialized syntax. You can define variables using the @name = value syntax and reference them in your requests using {{name}}.

    @user = doe
    @password = 12345678
    
    GET https://httpbin.org/basic-auth/{{user}}/{{password}}
    Authorization: Basic {{user}}{{password}}
  2. Configure Environment Settings

    main

    Manage how environments and variables are loaded and selected.

    | Name                                 | Description                                                                 | Default                                   |
    | ------------------------------------ | --------------------------------------------------------------------------- | ----------------------------------------- |
    | `httpyac.environmentSelectedOnStart` | list of selected environments on startup                                    | -                                         |
    | `httpyac.environmentPickMany`       | allow picking many environments at the same time                            | `true`                                    |
    | `httpyac.environmentVariables`       | environment variables                                                       | `{ "$shared":{} }`                      |
    | `httpyac.envDirName`                 | relative or absolute path to folder with dotenv files                       | `"env"`                                  |
  3. Determine the language ID for response content

    main

    The extension automatically selects a VS Code language ID for displaying response content based on the contentType (MIME type) and the responseViewContent mode.

    If responseViewContent is set to anything other than body (e.g., headers, full, or exchange), the language ID defaults to http.

    If responseViewContent is body, the following mapping logic is used:

    1. Check responseViewLanguageMap in settings for a custom MIME type mapping.
    2. If no custom mapping exists, use built-in defaults:
      • JSON MIME types $\rightarrow$ json
      • JavaScript MIME types $\rightarrow$ javascript
      • XML or HTML MIME types $\rightarrow$ html
      • CSS MIME types $\rightarrow$ css
      • Markdown MIME types $\rightarrow$ markdown
    3. Fallback to plaintext.
  4. Configure httpYac Extension Settings

    main

    General extension behavior settings such as gutter icons, logging, and history limits.

    | Name                             | Description                                     | Default |
    | -------------------------------- | ----------------------------------------------- | ------- |
    | `httpyac.showGutterIcon`          | show gutter icon to highlight request lines    | `true`  |
    | `httpyac.useMethodInSendCodeLens` | use request method in send code lens            | `false` |
    | `httpyac.logLevel`               | log level of output channel                     | `warn`  |
    | `httpyac.maxHistoryItems`        | number of max history items                     | `50`    |
  5. How environment selection and persistence works

    main

    When you select an environment using selectEnvironment, the extension updates the DocumentStore and fires an environmentChanged event.

    If the configuration environmentSelectedOnStart is set to true, the selected environment is persisted in your VS Code workspace settings under the environmentSelectedOnStart key, allowing it to be automatically restored when you open the project.

  6. Configure Request Settings

    main

    Use these settings to customize how requests are executed and how cookies are handled. Note that httpYac uses the standard VS Code proxy settings (http.proxy).

    | Name                            | Description                                                                                             | Default                      |
    | ------------------------------- | -------------------------------------------------------------------------------------------------------- | ---------------------------- |
    | `httpyac.requestDefaultHeaders` | default request headers if not overwritten                                                              | `{ "User-Agent": "httpyac"}` |
    | `httpyac.requestGotOptions`     | [request options](https://github.com/sindresorhus/got/blob/main/source/types.ts#L96) used for [got](https://www.npmjs.com/package/got) | -                            |
    | `httpyac.cookieJarEnabled`      | is [CookieJar](https://github.com/salesforce/tough-cookie#cookiejarstore-options) support enabled              | `true` or options            |
  7. Configure Response View Settings

    main

    Customize how the response is displayed in the editor, including headers, pretty-printing, and layout.

    | Name                                         | Description                                                                                                                                                                                                 | Default                                     |
    | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
    | `httpyac.responseViewHeader`                | headers (e.g. content-type), test results (e.g. tests.failed), timings (e.g. timings.total) and meta data (e.g. meta.size) visible in code lens of response                                                              | `[ "timings.total", "content-type", "content-length" ]` | 
    | `httpyac.responseViewMode`                  | response view mode of file                                                                                                                                                                                                | `preview`                                   |
    | `httpyac.responseViewPrettyPrint`          | response view pretty prints content. Pretty print is only working, if editor receives focus (vscode limitation)                                                                                                            | `true`                                      |
    | `httpyac.responseViewPreserveFocus`         | response view will not take focus after receiving response                                                                                                                                                                | `true`                                      |
    | `httpyac.responseViewColumn`                | response preview column option (current, beside)                                                                                                                                                                          | `beside`                                    |
    | `httpyac.responseViewLanguageMap`          | mimetype to [languageId](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) map for response view (only used if not in preview mode)                                                              | `beside`                                    |
  8. Configure response view modes and content

    main

    The responseViewMode setting determines how HTTP responses are displayed in the editor. The available modes are:

    • none: Disables response previewing.
    • preview: Opens the response in a preview tab (does not replace the current editor).
    • reuse: Reuses existing response files where possible.

    Additionally, the responseViewContent setting controls which parts of the HTTP exchange are visible:

    • body: Shows only the response body.
    • headers: Shows only the response headers.
    • full: Shows the full response (status line, headers, and body).
    • exchange: Shows the complete HTTP exchange, including the request (method, URL, headers, and body) followed by the response.

    Other related settings include:

    • responseViewPrettyPrint: When enabled, uses the pretty-printed version of the response body if available.
    • responseViewLanguageMap: A mapping of MIME types to VS Code language IDs to ensure correct syntax highlighting.
  9. Configure the Environment Status Bar Item

    main

    The extension can display the active environment in the VS Code Status Bar. This is controlled via the following configuration keys:

    • environmentShowStatusBarItem: Boolean to enable/disable the status bar item.
    • environmentStatusBarItemDefaultBackground: Sets the default background color for the status bar item. Supported values: 'none', 'warning', 'error'.
    • environmentStatusBarItemErrorEnvs: An array of environment names that, if active, will force the status bar to use the error theme color.
    • environmentStatusBarItemWarningEnvs: An array of environment names that, if active, will force the status bar to use the warning theme color.
  10. Configure httpYac CodeLens behavior

    main

    The extension can display CodeLens in your HTTP files to quickly manage environments and sessions. These are controlled via the codelens configuration object.

    Supported CodeLens options:

    • pickEnvironment: If enabled, displays a CodeLens at the top of the file showing the current active environment (e.g., env: dev, staging). Clicking it triggers the toggle-env command.
    • resetEnvironment: If enabled, displays a reset environment CodeLens.
    • logoutUserSession: If enabled and active sessions exist, displays a session (N) CodeLens to manage user sessions.

    Note: CodeLens is disabled in Notebooks unless useCodeLensInNotebook is set to true in your configuration.

  11. Configure httpyac via ResourceConfig

    main

    The ResourceConfig interface defines settings that can be scoped to specific files or workspaces. These settings influence how individual HTTP requests are executed. Key options include:

    • Request Headers & Body: requestDefaultHeaders (a record of headers) and requestBodyInjectVariablesExtensions (an array of file extensions for variable injection).
    • Environment Variables: environmentVariables allows defining variables specific to the resource.
    • Cookie & Proxy Settings: cookieJarEnabled (boolean or detailed object) and proxyExcludeList (array of strings) manage network behavior.
    • Certificates: clientCertificates allows providing httpyac.ClientCertificateOptions for authenticated requests.
    • Logging: logRequest (boolean) and logOutputChannelOptions control request logging.
  12. Configure httpyac via AppConfig

    main

    The AppConfig interface defines the global VS Code settings for the httpyac extension. These settings control the behavior of the UI, response viewing, code generation, and testing. Key configuration areas include:

    • Environment Management: environmentSelectedOnStart, environmentShowStatusBarItem, and environmentPickMany control how environments are selected and displayed.
    • Response Viewing: responseViewMode ('preview' | 'reuse' | 'open' | 'none'), responseViewContent ('body' | 'headers' | 'full' | 'exchange'), and responseViewPrettyPrint control how HTTP responses are rendered.
    • Code Generation: generateCodeDefaultLanguage and generateCodeTargetOutput ('clipboard' | 'window') configure the default output for the code generation feature.
    • Testing: testControllerEnabled, testMaxConcurrency, and testBailOnFailedTest manage the behavior of the integrated test runner.
    • CodeLens: The codelens object allows enabling or disabling specific UI elements like send, generateCode, or testResult.