
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@iyulab/http-test
Advanced tools
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.
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.
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
http-test uses a simple syntax for defining API tests in .http files:
Check the status code of the response:
### GET all users
GET {{host}}/users
#### Assert: Check status code
Status: 200
Assert response headers:
### GET all users
GET {{host}}/users
#### Assert: Check headers
Status: 200
Content-Type: application/json
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
Save values from the response to use in subsequent requests:
### POST new user
POST {{host}}/users
Content-Type: application/json
{
"name": "Alice Johnson",
"email": "alice@example.com"
}
#### Assert: Check new user creation
Status: 201
Content-Type: application/json
Body:
$.name: Alice Johnson
$.email: alice@example.com
# Save new user ID to variable
@newUserId = $.id
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
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.
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
FAQs
API testing library, by .http files, Automatic assertion
We found that @iyulab/http-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.