npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ln-maf/api

v3.0.1

Published

MAF module providing API steps

Downloads

4,359

Readme

MAF - API Module

This module is created to allow other projects to easily perform API requests, utilizing a set of steps.

npm package GitHub Actions

Dependencies

This module is dependent on the following npm modules:

  • fetch-blob
  • node-fetch
  • form-data
  • fetch-to-curl

Set up

  1. Install by running npm i @ln-maf/api

  2. Add a new step file in the features folder with the following code:

require('@ln-maf/api')

Global MAF API Variables

  • url: The url to use for the api request. Should be a string including the protocol. ex: 'https://google.com'
  • api: The api to use for the api request. Should be a string. ex: 'driver/users/1'
  • body: The body to use for the api request. Should be a string.
  • jsonBody: The json body to use for the api request. It must be in a valid JSON object format
  • urlEncodedBody: The url encoded body to use for the api request. It will be appended to the url
  • headers: The headers to use for the api request. Should be a JSON object. Note that the default headers are remove if this is used. The default headers are documented here in the node-fetch documentation.
  • method: The method to use for the api request. Should be a string. ex: 'GET', 'POST', 'PUT', 'DELETE'

Step Definitions

Given url {string}

Deprecated: Set the item 'url' instead

Assigns a string to the url item

Given api {string}

Deprecated: Set the item 'api' instead

Assigns a string to the api item

Given body {string}

Deprecated: Set the item 'body' instead

Defines the body for a given request

Given headers {string}

Deprecated: Set the item 'headers' instead

Takes a string of headers. These should represent a json object. Note that the default headers are removed if this is used. The default headers are documented here in the node-fetch documentation.

When api request from{jsonObject}is performed

Performs a request based on the json file and given values. An example json file would be:

{
    "api": "driver/users/1",
    "method": "POST",
    "headers": {
      "Accept": "application/json",
      "X-Api-Service-Version": "2.0",
      "Content-Type": "application/json",
      "X-AliasRequired": false
    },
    "body": {
      "clientNumber" : "111",
      "email": "1@1.com"
      "mobilePhone":"1"
    }
  }

After the request is performed, the results will be stored in ${lastRun} consistent with the global cucumber testing standard, and in ${response}. This can be accessed in other tests following this standard with the template literal ${lastRun} or ${response}.

When api request is performed

Performs a request based on the global variables set. The global variables are listed above.

When perform api request: {docString}

Performs using a doc string instead of a file. Please see When api request {string} is performed

Example:

When perform api request:
"""
{
  "url" : "http://google.com",
  "method": "GET"
}
"""

How to perform a multi-part request

The request supports and additional body type of: formBody. This supports arrays(untested) and will append it to element + [].
As of now the only portion of this that is tested and is not included in this CI is the file. Hopefully this will be tested in more detail soon.

An example would be:

{
    "api": "/driver/upload?ft=1&fn=${outputFilename}",
    "headers": {
        "X-Api-Key": "${apiKey}",
        "X-File-Format": "DECRYPTED",
        "X-File-Format-Version": "4.0",
        "accept": "application/json",
        "accept-encoding": "gzip",
        "accept-language": "en-US,en;q=0.9",
        "authorization": "Bearer ${a_t}",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "x-api-service-version": "1.0"
    },
    "formBody": {
      "file": {
        "type": "file",
        "fileName": "${outputFilename}"
      },
      "stringParam": "string",
      "numParam": 3,
      "blobParam": {
        "type": "base64blob",
        "base64blob": "SEVMTE8gV09STEQ="
      },
      "stringArray": ["hello", "world"],
      "fileArray": [
        {
          "type": "file",
          "fileName": "${outputFilename}"
        },
        {
          "type": "file",
          "fileName": "${outputFilename2}"
        }
      ]
    },
    "method": "POST"
}

When method post

Deprecated: Set the item 'method' to 'POST' and call the method 'api request is performed' instead

Performs a post using the defined values listed above and stores the result in this.results.lastRun which can be accessed with ${lastRun}

When method get

Deprecated: Set the item 'method' to 'GET' and call the method 'api request is performed' instead

Performs a post using the defined values listed above and stores the result in this.results.lastRun which can be accessed with ${lastRun}

Then the status is ok

Makes sure that response.status is between 200 and 299.

Then status ok

Deprecated: Use the status is ok, the status is {int} or the status is not ok instead

Makes sure that response is between 200 and 299.

Then the status is not ok

Makes sure that response.status is not between 200 and 299.

Then status not ok

Deprecated: Use the status is ok, the status is {int} or the status is not ok instead

Makes sure that response.status is not between 200 and 299.

Then the status is {int}

Makes sure that response.status is equal to the integer specified.

Then status {int}

Deprecated: Use the status is ok, the status is {int} or the status is not ok instead

Makes sure that response.status is equal to the integer specified.