express-seekret-traffic-capture v0.1.1
express-seekret-traffic-capture
An express middleware for capturing the API traffic of an express server.
The traffic is captured in JSON files in a local directory (.seekret
by default), and can be uploaded to the Seekret platform using the Seekret CLI.
:warning: This should be used in test environment only, since it keeps the full HTTP requests' data.
Installation
npm install --save express-seekret-traffic-capture
or
yarn add express-seekret-traffic-capture
Usage example
You can import the middleware by using either of these statements:
const { seekretRequestsHandler } = require('express-seekret-traffic-capture')
or:
import { seekretRequestsHandler } from 'express-seekret-traffic-capture'
Then, use the middleware in your express application.
:warning: It's recommeneded to use the middleware only in specific environments or when running tests.
const app = express()
if (env === 'TEST') {
// will write requests to 'requests' directory with the service name 'my-service' as request metadata
app.use(seekretRequestsHandler({directory: 'requests', serviceName: 'my-service'}))
}
app.use(myTestHandler)
app.get('/', (req, res) => {
res.status(200).send('Hello World!')
})
app.listen(port)
Uploading traffic to the Seekret platform
Prerequisites
Guide
The captured traffic can be uploaded to the Seekret platform by using the seekret map main
or the seekret map snapshot
commands:
seekret map snapshot -d ./.seekret --snapshot-name "My Snapshot" --plan-name pr-tests
❕Modify the snapshot and plan names to match your intended names
After running the command you should expect to see the following output:
Mapping API inventory...◒ Finished Mapping!
Snapshot "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" was created successfully
To see the API inventory of the created snapshot, press the link below:
https://app.seekret.io/workspaces/{workspace}/snapshots/{snapshot_id}/inventory
Horray! You officially uploaded a new API inventory! You can use the link to browse the uploaded inventory.