agrostar / zzapi-vscode

VS Code extension for zzapi - an API testing and documentation framework
MIT License
3 stars 0 forks source link
api api-client api-rest testing typescript vscode-extension

zzAPI Visual Studio Code Extension

zzAPI (prounounced like pizza, the syllables interchanged) is an HTTP (REST) API documentation and testing tool, a very simplified version of Postman. It uses zzAPI core as the underlying engine.

This extension makes it easy to create, document and test API requests from within the IDE. Request bundles are YAML files with the .zzb extension.

License Installs Version Stars

Features

screencast

Getting Started

  1. Install the RedHat YAML extension. This is not strictly needed, but the formatting and schema validation is really helpful and useful.
  2. Start creating a request bundle. Here is a very simple example:
requests:
  simple-get:
    method: GET
    url: https://postman-echo.com/get
    params:
      foo1: bar1
  1. Save the The file with a .zzb file extension to activate the extension.
  2. Alternatively import a Postman collection:
    • Export the Postman collection as a JSON (v2.0.1) schema
    • Use the command pallete in VS Code (Cmd-Shift-P or Ctrl-Shift-P) and choose zzAPI: Import Postman collection
    • In the File Open dialog, choose the Postman collection you exported in the first step
    • The command will open a new editor window and place the converted YAML. Save it to a file with a .zzb extension
    • If you have used variables in Postman, you can also import the environments in a similar manner: export them in Postman and import them in VS Code.
  3. You will see a CodeLens above each named request for running the request. You will also see a CodeLens above the requests node, to run all the requests sequentially. Click on these to execute them and see the response.

A POST request with headers

requests:
  simple-post:
    method: GET
    url: https://postman-echo.com/post
    headers:
      Content-type: application/json
      Authorization: Basic Xfj34$fe
    body:
      foo1: bar1
      foo2: [ bar2, bar3 ]

Testing response values

requests:
  get-with-params:
    method: GET
    url: https://postman-echo.com/get
    params: { foo1: bar1, foo2: bar2 }
    tests:
      status: 200
      $.args.foo1: bar1
      $.args.foo2: bar2

Variables

Define

Within the bundle:

variables:
  staging:
    server: https://staging.example.com
    expectedUserId: 12345
  production:
    expectedUserId: 45678
    server: https://www.example.com

In a separate .zzv file (shared across multiple bundles in the directory):

staging:
  user: staging-user
  password: staging-password
production:
  user: user
  password: password

Set from response fields

requests:
  get-with-params:
    method: GET
    url: https://example.com/login
    params: { userId: bar1, password: bar2 }
    setvars:
      userName: $.data.name

Usage

requests:
  login:
    url: $server/login
    method: GET
    params: { user: $user, password: $password }
  tests:
    status: 200
    $.userDetails.userId: $expectedUserId

Options

requests:
  simple-get:
    url: $server/get
    method: GET
    params: { foo: foo%20bar }
    options:
      rawParams: true
      follow: true

Share common things across requests

common:
  baseUrl: https://postman-echo.com
  headers:
    Content-type: application/json
  tests:
    status: 200
  options:
    follow: true

requests:
  Simple GET:
    url: /get
    method: GET

Sample responses

  simple-get:
    url: $server/get
    method: GET
    params: { foo: bar }
    response-normal: file://./responses/normal.json
    response-failure: file://./responses/failure.json

Detailed Usage

The extension works with .zzb files, which are YAML request bundles as described here.

You can use variables within the bundle, and also common variable set files and environments as described here.

You can best learn about the .zzb file format by just browsing the bundle used for comprehensively testing zzAPI itself: tests-bundle.zzb.

Tips and Tricks

  body: |-
    <xml>
      <node value="x"/>
    </xml>

Feedback, bugs and feature requests

To appreaciate, give us a star in the GitHub repo: https://github.com/agrostar/zzapi-vscode and/or in the VS Code marketplace: https://marketplace.visualstudio.com/items?itemName=AgroStar.zzapi

For bugs, improvements and feature requests, create a new issue here:

https://github.com/agrostar/zzapi-vscode/issues