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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iyulab/http-test

v1.0.19

Published

API testing library, by .http files, Automatic assertion

Downloads

201

Readme

http-test

http-test is a powerful and user-friendly API testing library that allows you to easily write and execute API tests using simple .http files. With http-test, you can streamline your API testing process and ensure the reliability of your endpoints without writing complex test scripts.

VS Code Extension

For an even easier experience, use the http-test VS Code Extension. This extension provides seamless integration with Visual Studio Code, allowing you to run and manage your http-test files directly from the editor.

VS Code Extension Screenshot

Features

  • Write tests in easy-to-read .http files
  • Support for various HTTP methods (GET, POST, PUT, DELETE, PATCH)
  • Automatic assertion based on status codes
  • Custom assertions for headers, body content, and more
  • Variable management for dynamic request data
  • File upload testing support
  • Detailed test reports and summaries

Installation

Install http-test globally using npm:

npm install @iyulab/http-test -g

Once installed, run your tests with:

http-test path/to/your/tests.http
http-test path/to/your/tests.http --verbose

Writing Tests

http-test uses a simple syntax for defining API tests in .http files:

Status Code Assertions

Check the status code of the response:

### GET all users
GET {{host}}/users

#### Assert: Check status code
Status: 200

Header Assertions

Assert response headers:

### GET all users
GET {{host}}/users

#### Assert: Check headers
Status: 200
Content-Type: application/json

JSONPath Assertions

Use JSONPath to assert specific values in the response body:

### GET all users
GET {{host}}/users

#### Assert: Check response body
Status: 200
Content-Type: application/json
Body:
$[0].id: 1
$[0].name: John Doe

Setting Variables from Response

Save values from the response to use in subsequent requests:

### POST new user
POST {{host}}/users
Content-Type: application/json

{
  "name": "Alice Johnson",
  "email": "[email protected]"
}

#### Assert: Check new user creation
Status: 201
Content-Type: application/json
Body:
$.name: Alice Johnson
$.email: [email protected]

# Save new user ID to variable
@newUserId = $.id

Custom Assertions with Scripts

Write custom JavaScript functions for complex validations:

// custom-assert.js
module.exports = function(response, context) {
  const body = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;

  if (body.id !== context.variables.newUserId) {
    throw new Error("User ID mismatch");
  }

  if (!body.email.includes('@')) {
    throw new Error("Invalid email format");
  }
};

Use the custom assertion in your .http file:

### Custom Assert user verification 
GET {{host}}/users/{{newUserId}}

#### Assert: Verify user format
Status: 2xx
_CustomAssert: ./custom-assert.js

File Uploads

Test file uploads using multipart/form-data:

### Upload file
POST {{host}}/upload
Content-Type: multipart/form-data; boundary=---boundary
Content-Disposition: form-data; name="file"; filename="example.txt"

This is the content of the file.

Using External Variable Files

Manage variables using a variables.json file:

// variables.json
{
  "host": "http://localhost:3000",
  "token": 123
}

Reference these variables in your .http test files:

@host = http://localhost:3000

### GET all users
GET {{host}}/users