- hopp [Experimental]
- pw [Legacy]
It is not recommended to migrate or reformat your existing scripts to the new scripting APIs at this time. Upcoming updates are expected to introduce breaking changes as we continue to refine and improve the scripting experience.The current rollout is intentionally gradual, allowing us to gather user feedback and iterate based on real-world usage.All further updates to scripting will be scoped to the experimental scripting sandbox, which is the default, and the preference can be updated from
Settings → Experiments
.Your feedback will be invaluable as we shape the next generation of Hoppscotch scripting.This new experimental implementation provides a robust foundation for API scripting with enhanced capabilities for environment management, request manipulation, response processing, cookie handling, and comprehensive testing. The new system maintains backwards compatibility while introducing powerful new features for modern API testing workflows.
hopp.env
Namespace
Environment variable management with scope-specific operations and enhanced functionality.hopp.env.get(key: string)
Retrieves the value of the selected environment’s variable. Accepts an environment variable as an argument.hopp.env.getRaw(key: string)
Retrieves the raw value of the selected environment’s variable without variable resolution.hopp.env.set(key: string, value: string)
Sets the value of an environment variable in the selected environment.hopp.env.delete(key: string)
Deletes an environment variable from the selected environment.hopp.env.reset(key: string)
Resets an environment variable to its initial value in the selected environment.hopp.env.getInitialRaw(key: string)
Retrieves the initial raw value of an environment variable.hopp.env.setInitial(key: string, value: string)
Sets the initial value of an environment variable.Active Environment Scope
Operations specific to the currently active environment.hopp.env.active.get(key: string)
Retrieves the value of the active environment’s variable.hopp.env.active.getRaw(key: string)
Retrieves the raw value of the active environment’s variable.hopp.env.active.set(key: string, value: string)
Sets the value of an active environment variable.hopp.env.active.delete(key: string)
Deletes a variable from the active environment.hopp.env.active.reset(key: string)
Resets a variable in the active environment to its initial value.hopp.env.active.getInitialRaw(key: string)
Retrieves the initial raw value of an active environment variable.hopp.env.active.setInitial(key: string, value: string)
Sets the initial value of an active environment variable.Global Environment Scope
Operations specific to the global environment.hopp.env.global.get(key: string)
Retrieves the value of the global environment’s variable.hopp.env.global.getRaw(key: string)
Retrieves the raw value of the global environment’s variable.hopp.env.global.set(key: string, value: string)
Sets the value of a global environment variable.hopp.env.global.delete(key: string)
Deletes a variable from the global environment.hopp.env.global.reset(key: string)
Resets a variable in the global environment to its initial value.hopp.env.global.getInitialRaw(key: string)
Retrieves the initial raw value of a global environment variable.hopp.env.global.setInitial(key: string, value: string)
Sets the initial value of a global environment variable.The hopp.request
Namespace
Request manipulation with immutable properties and dedicated mutation functions.Read-only Properties
hopp.request.url
The request URL as a string.hopp.request.method
The HTTP method of the request.hopp.request.params
The query parameters of the request.hopp.request.headers
The headers of the request.hopp.request.body
The body of the request.hopp.request.auth
The authentication configuration of the request.Mutation Functions (Pre-request Phase Only)
hopp.request.setUrl(url: string)
Sets the request URL.hopp.request.setMethod(method: string)
Sets the HTTP method of the request.hopp.request.setHeader(name: string, value: string)
Sets a header on the request.hopp.request.setHeaders(headers: HoppRESTHeader[])
Sets multiple headers on the request.hopp.request.removeHeader(name: string)
Removes a header from the request.hopp.request.setParam(name: string, value: string)
Sets a query parameter on the request.hopp.request.setParams(params: HoppRESTParam[])
Sets multiple query parameters on the request.hopp.request.removeParam(name: string)
Removes a query parameter from the request.hopp.request.setBody(body: Partial<HoppRESTReqBody>)
Sets the body of the request.hopp.request.setAuth(auth: Partial<HoppRESTAuth>)
Sets the authentication for the request.Request Variables
hopp.request.variables.get(key: string)
Retrieves the value of a request variable.hopp.request.variables.set(key: string, value: string)
Sets the value of a request variable.Please note that only updates to request variables get persisted and reflected in the UI while the remaining are specific to the session.
The hopp.response
Namespace
Response access with multiple data formats and comprehensive metadata.Response Metadata
hopp.response.statusCode
The HTTP status code of the response.hopp.response.statusText
The status text of the response.hopp.response.headers
The headers of the response.hopp.response.responseTime
The response time in milliseconds.Response Body Access Methods
hopp.response.body.asJSON()
Parses the response body as JSON.hopp.response.body.asText()
Returns the response body as text.hopp.response.body.bytes()
Returns the response body as a Uint8Array.The hopp.cookies
Namespace
Domain-aware cookie management with comprehensive CRUD operations.hopp.cookies.get(domain: string, cookieName: string)
Retrieves a cookie by domain and name.hopp.cookies.set(domain: string, cookie: Cookie)
Sets a cookie for a domain.hopp.cookies.has(domain: string, cookieName: string)
Checks if a cookie exists for a domain.hopp.cookies.getAll(domain: string)
Retrieves all cookies for a domain.hopp.cookies.delete(domain: string, cookieName: string)
Deletes a cookie for a domain.hopp.cookies.clear(domain: string)
Clears all cookies for a domain.The hopp.test
and hopp.expect
Testing Framework
Comprehensive testing API with custom assertions for API testing.hopp.test(testName: string, testFunction: () => void)
Creates a group of tests with a name.hopp.expect(actual: any)
Returns an expectation object for assertions.Basic Custom Assertions
hopp.expect(value).toBe(expected: any)
Tests for exact equality.hopp.expect(value).toBeType(type: string)
Tests for type equality.hopp.expect(value).toHaveLength(number: number)
Tests that a value has a specific length.hopp.expect(value).toInclude(item: any)
Tests that a value includes an item.HTTP Status Code Level Assertions
hopp.expect(statusCode).toBeLevel2xx()
Tests that the status code is in the 2xx range.hopp.expect(statusCode).toBeLevel3xx()
Tests that the status code is in the 3xx range.hopp.expect(statusCode).toBeLevel4xx()
Tests that the status code is in the 4xx range.hopp.expect(statusCode).toBeLevel5xx()
Tests that the status code is in the 5xx range.Negation Support
All assertions support.not
for negation.