Freedom251 › API Mocking Tools
Pretender.js

What Pretender.js is
Pretender.js is a free, open-source library for creating mock servers for XMLHttpRequest and Fetch in browser applications. Developers define routes and handlers using a syntax similar to Express or Sinatra, with methods for GET, PUT, POST, DELETE, PATCH, and HEAD. A handler can provide an HTTP status, headers, and body, or return a Promise. Responses can be synchronous, asynchronous, delayed, or held until manually resolved. Routes can also pass requests through to native XMLHttpRequest. Pretender tracks registered handlers and handled, unhandled, and pass-through requests, with an option to turn tracking off. It temporarily replaces native XMLHttpRequest and Fetch, and works only in the browser. The project documents installation as a development dependency with npm or Yarn, as well as direct browser loading and module imports. When finished, users should call shutdown() to restore the native XMLHttpRequest object. The project uses the MIT license, which permits use, modification, distribution, sublicensing, and sale without charge. Its repository has an Issues page for discussion and reports.
Who it suits
Pretender.js suits developers who need browser-based mocks for XMLHttpRequest and Fetch, including control over routes and response timing. It is limited to browser use.
What it does well
- Supports XMLHttpRequest and Fetch mocks in the browser
- Offers six route methods
- Controls response timing, including manual resolution
- Routes can pass through to native XMLHttpRequest
- MIT license permits use and modification without charge
What to know first
- Works only in the browser
- Temporarily replaces native XMLHttpRequest and Fetch
- Users must call shutdown() to restore native XMLHttpRequest
Getting started
- Install Pretender as a development dependency with npm or Yarn
- Load it directly in a browser or import it as a module
- Define routes with the provided HTTP methods and handlers
- Configure response timing, pass-through, or request tracking as needed
- Call shutdown() when finished to restore native XMLHttpRequest
Verdict
Pretender.js provides flexible browser request mocking with route tracking and timing controls. Its browser-only scope makes it unsuitable for use outside the browser.
Questions
Is Pretender.js free?
Yes. It is free and open source, and the repository uses the MIT license.
Which platforms does it support?
Pretender.js works in web browsers only.
How can it be installed?
The README shows npm and Yarn development-dependency commands, direct browser loading, and module importing.
What request methods can routes use?
The routing DSL provides get, put, post, delete, patch, and head methods.
Can routes pass requests through?
Yes. Routes can be configured to forward requests to native XMLHttpRequest calls.
How is the native request object restored?
Call shutdown() when you are finished to restore the native XMLHttpRequest object.
Facts from Pretender.js's own pages
- Browser only
- Pretender temporarily replaces native XMLHttpRequest and Fetch to intercept requests, and the README says it only works in the browser. · github.com, 11 Oct 2026
- Cleanup
- The README instructs users to call shutdown() when finished to restore the native XMLHttpRequest object. · github.com, 11 Oct 2026
- Installation
- The README shows installation with yarn add -D pretender or npm install --save-dev pretender. · github.com, 4 Oct 2026
- License
- The package metadata identifies the license as MIT. · github.com, 11 Oct 2026
- Maintenance activity
- The Pretender organization page lists the repository as updated Jan 29, 2024. · github.com, 11 Oct 2026
- Module use
- The README shows Pretender loaded directly in a browser or imported as a module. · github.com, 4 Oct 2026
- Pass-through
- Configured requests can pass through Pretender and be sent as real XMLHttpRequests. · github.com, 11 Oct 2026
- Purpose
- Pretender is a mock server library for XMLHttpRequest and Fetch with an Express/Sinatra-style routing syntax. · github.com, 4 Oct 2026
- Request tracking
- Pretender tracks handled, unhandled, and pass-through requests, and request tracking can be disabled with an option. · github.com, 11 Oct 2026
- Responses
- Route handlers can return a response array containing an HTTP status, headers, and body, or return a Promise. · github.com, 11 Oct 2026
- Response timing
- Routes can respond asynchronously, synchronously, after a delay, or only when manually resolved. · github.com, 4 Oct 2026
- Route methods
- The routing DSL supports GET, PUT, POST, DELETE, PATCH, and HEAD methods. · github.com, 11 Oct 2026
- Support and community
- The project asks community members to follow its Code of Conduct and directs reports to a maintainer. · github.com, 4 Oct 2026
- Support channel
- The project repository provides an Issues page for reporting and discussing issues. · github.com, 11 Oct 2026
- Timing controls
- Routes can respond asynchronously, synchronously, after a delay, or only when manually resolved. · github.com, 11 Oct 2026
- Usage
- The README documents installation with npm or Yarn, direct browser script loading, and importing Pretender as a module. · github.com, 11 Oct 2026
- What it does
- Pretender is a mock server library for XMLHttpRequest and Fetch with an Express- or Sinatra-style syntax for defining routes and handlers. · github.com, 11 Oct 2026
Where Pretender.js stands on Freedom251
- API Mocking Tools#23 of 26