
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
To send fake request to a Koa application without starting a http server. So that, you can require a Koa app into your code.
To send fake request to a Koa application without starting a http server.
Sending multipart
data will be supported later.
$ npm i koa-sham --save
const Koa = require( 'koa' );
const sham = require( 'koa-sham' );
const app = new Koa();
app.use( ctx => {
ctx.body = { status : 1 };
} );
sham( app, ( err, res, body ) => {
console.log( body ); // { status : 1 }
} );
sham( app, {
qs : {
x : 1
}
}, ( err, res, body ) => {
console.log( body ); // { status : 1 }
} );
sham( app, '/path', { https: true }, ( err, res, body ) => {
console.log( body ); // { status : 1 }
} );
sham( app, {
method : 'POST',
body : {
x : 1
}
}, ( err, res, body ) => {
console.log( body ); // { status : 1 }
} );
sham( app, { promise : true } ).then( data => {
console.log( data );
} );
sham( app ).pipe( process.stdout );
Returns a Readable Stream
by default, but can be changed by using { promise : true }
in options
.
app
The instance of Koa
application.
url
Type: String
The URL
or PATH
the you want to request. The host of the URL will be set as 127.0.0.1
by default. The protocol will be set to http
if options.https
is not true
. The default port is 80
and it can be changed with options.port
.
If the protocol of the URL is https
, the request will be set to secure
, even thought the options.https
is not set to true
.
options
Type: Object
Options for the fake request.
remoteAddress String
The remote IP address, 127.0.0.1
by default.
host String
The host of URL, this item will be ignored if the passed URL
contains it's host.
port Number
The port of URL, this item will be ignored if the passed URL
contains it's host.
https Boolean
To set the request to secure
, this item will be ignored if the passed URL
contains it's protocol and is not 'https'.
method String
The request method
qs Object
The query string, should be an object.
headers Object
The headers of the request.
cookies Object
The cookies that will be set while sending request, it will overwrite the same cookie which is also in headers
.
body Object
String
The request body for POST
or PUT
request.
promise Boolean
If promise
is true, the function will return a Promise
object.
**resolveWithFullResponse Boolean
By setting this option to true
, the returned promise
will use the full response data as it's value.
FAQs
To send fake request to a Koa application without starting a http server. So that, you can require a Koa app into your code.
The npm package koa-sham receives a total of 117 weekly downloads. As such, koa-sham popularity was classified as not popular.
We found that koa-sham demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.