@snapiapp/snapi-client
v0.1.0
Published
Snapi client SDK for logging API calls
Maintainers
Readme
@snapiapp/snapi-client
Log API calls to Snapi with one middleware line.
Install
npm i @snapiapp/snapi-client
### Usage (Express)
var express = require('express');
var snapi = require('@snapiapp/snapi-client');
var app = express();
// If you want Snapi to capture request bodies, JSON parsing must run BEFORE it.
app.use(express.json());
app.use(snapi.expressMiddleware({
apiKey: process.env.SNAPI_API_KEY,
apiUrl: process.env.SNAPI_API_URL, // include /logs
captureRequestBody: true,
captureResponseBody: 'errors', // true | false | 'errors'
ignorePathPrefixes: ['/health', '/favicon.ico']
}));
app.get('/ping', function (req, res) {
res.json({ ok: true });
});
app.listen(3000, function () {
console.log('Listening on :3000');
});
### Environment variables
SNAPI_API_KEY — your project key
SNAPI_API_URL — ingest endpoint (example: https://snapi-api.projektmind.com/logs)
### Options
ignorePathPrefixes (array of strings) — skip logging for paths that start with these prefixes
Example: ['/health', '/favicon.ico']
Tip: do not include '/' or it will skip everything.
captureRequestBody (boolean) — include req.body (requires express.json() before the middleware)
captureResponseBody (false | true | 'errors') — capture response body for all requests, or only error responses
### Exports
var snapi = require('@snapiapp/snapi-client');
// snapi.SnapiClient
// snapi.createClient(options)
// snapi.expressMiddleware(options)