Complete local example

Minimal end-to-end example from Gherkin to generated tests and report.

This walkthrough uses Restlyn’s included mock API and a new local project. It does not require a public API account or service credentials. Use Node.js 18 or newer and a CommonJS project for the generated .test.js files.

1. Install in a new project

mkdir restlyn-first-run
cd restlyn-first-run
npm init -y
npm install --save-dev restlyn@0.1.1

Start the local demo API

In a separate terminal, from the same project directory:

restlyn mock

For a local package installation, use npx --no-install restlyn mock instead. The included mock API listens on port 4000. If you are also previewing this Jekyll site locally on port 4000, restart Jekyll with bundle exec jekyll serve --port 4001 and browse the docs on port 4001 first. Do not stop another service without checking what owns the port.

The following example uses the mock’s synthetic login credentials user@example.com / secret. Stop the mock with Ctrl+C after testing.

2. Create a feature file

Create a features folder. Save this as features/login.feature:

Feature: Local login API

  Scenario: Valid login returns a token
    Given base URL is "http://127.0.0.1:4000"
    When I POST "/login" with:
      | email    | user@example.com |
      | password | secret           |
    Then response status should be 200
    And response body should contain key "token"

3. Generate the step map and test

In another terminal, from restlyn-first-run:

npx --no-install restlyn steps --file login.feature --overwrite
npx --no-install restlyn tests --overwrite

The steps --file argument is relative to the feature root (normally features), so use login.feature here, not features/login.feature. Inspect generated/stepmaps/login.stepMap.json and generated/tests/login.test.js. Regenerate the test after changing the feature or generation settings. --overwrite replaces previously generated files.

4. Run the generated test

npx --no-install restlyn verify --json

The console should show a passing scenario. Inspect generated/report/restlyn-report.json for the recorded outcome.

5. Generate HTML and optional PDF reports

npx --no-install restlyn verify --report

The HTML report is generated/report/restlyn-report.html. The CLI attempts to open it in your browser. PDF export requires optional Puppeteer and its browser installation; see Reports. Keep the mock API running until the test finishes, then stop it with Ctrl+C.

Adapt the workflow

Use Configuration for paths, environments and headers; Writing Gherkin for supported steps; and Schemas for response contracts. Replace the demo URL and credentials with values for an API you are authorized to test.

Migrated from the Restlyn documentation, with reviewed example and configuration corrections. Original Restlyn documentation.